Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 148
  • Last Modified:

Dynamic listboxes -How?

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
RBertora
Asked:
RBertora
  • 2
1 Solution
 
MasseyMCommented:
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
 
MasseyMCommented:
In return, we can swap some Delphi code?
0
 
RBertoraAuthor Commented:
Thank you .
Rob.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now