Solved

Dynamic listboxes -How?

Posted on 1998-11-17
3
140 Views
Last Modified: 2013-12-25
Hi there, I've been coding in Delphi for a couple of years and
am very new to ASP,HTML,JavaScript. I am extremely frustrated
as what I am trying to do here would take me 5 mins in Delphi, so
hopefully for someone who knows this is an easy question.

I want two listboxes on a page. The first listbox should contain a list of areas
populated by a query to a DB. The second listbox initialy contains nothing,
but is populated with a list of towns that belong to a particular area(2nd query).
This should be a second query to the DB using the area selected as part of the criteria.

Thanks.


This is the sort of stuff I have been playing with:
? -indicates where I dunno what is happening

The first bit : populating the 1st list box works.

<!--#include file="style.inc"-->
<HTML>
  <HEAD>
    <TITLE>New Document</TITLE>
  </HEAD>
  <BODY>
  <FORM Action = "Messing.asp" Name = "ListBoxes" Method="POST" TARGET = "MainFrame">

  <%
    set ConnectionObject = Server.CreateObject("ADODB.Connection")
    ConnectionObject.open ConnectionParameters
    set RecordSet = Server.CreateObject("ADODB.RecordSet")
    RecordSet.ActiveConnection = ConnectionObject
    RecordSet.Source = "Select area,areacode from areas"
    RecordSet.Open

?    set RecordSet2 = Server.CreateObject("ADODB.RecordSet")
?    RecordSet2.ActiveConnection = ConnectionObject
?    RecordSet2.Source = "Select town from towns where areacode =" &AreaCode
?    Response.write(RecordSet2.Source)
?    RecordSet2.Open

  %>

<SCRIPT LANGUAGE="javascript">
  function DisplaySomething(AreaCode)
  {
?    Ideally would want to run a second query here but do not know
?    how exactly..
  }
</SCRIPT>

  Select a province:
  <SELECT Name = "ProvinceListBox"  onchange = ExecuteTownQuery(RecordSet(1) ????)>  
  <%do%>
     <OPTION value = "<%=Recordset(1)%>"> <% Response.write(RecordSet(0)) %>
  <% RecordSet.MoveNext
    loop while RecordSet.Eof = 0
  %>
  </SELECT>
  <%
    RecordSet.Close
  %>
  <P></P>
  <P></P>
  Select a Town:
  <SELECT Name = "TownsListBox">
  </SELECT>

  </FORM>
  </BODY>
</HTML>
0
Comment
Question by:RBertora
  • 2
3 Comments
 
LVL 10

Accepted Solution

by:
MasseyM earned 150 total points
ID: 1829641
Here is the problem:

You can run query 1 just fine and populate the box 1.  Then you would have to reload the page with box 1 selected, send that variable to the SP script and then run the second query according to the selection in box 1.  

In delphi, you ould use an if then statement...

If box1 = this then box2 items will be...

This type of stuff can be done in two ways.  
1) with javascript, but EVERY item from the database will have to be loaded.
2) Databinding would work.

You cannot run a 2nd query directly from the web page since ASP is a server side language.

here is something...

<% If request("ProvinceListBox") = "" then %>
   <FORM ACTION="thissamepage.asp" METHOD=POST
   Run your first query in here.
   Display the list of provinces and have a submit button.
<% Else %>
   this part will be accessed when the user presses the submit button from the code above.
   Run 2nd query with the value of listbox (that they entered before) as the search criteria.
<% End If %>

If this is confusing, please email me the database and your ASP pages so far.  I will see what I can do.

masseym@hotmail.com

0
 
LVL 10

Expert Comment

by:MasseyM
ID: 1829642
In return, we can swap some Delphi code?
0
 
LVL 7

Author Comment

by:RBertora
ID: 1829643
Thank you .
Rob.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How to count json data 2 66
scripting, exchange 35 46
Need to Modify a Script I found 5 92
Can I exclude specific directory with icacle command? 3 25
The following is a collection of cases for strange behaviour when using advanced techniques in DOS batch files. You should have some basic experience in batch "programming", as I'm assuming some knowledge and not further explain the basics. For some…
In this tutorial I will show you how to provide a dynamic RTF document on your website generated with data from your database. For this tutorial you will need Microsoft Word or WordPad, WhizBase and Microsoft Access. In this tutorial I will show …
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now