Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Dynamic listboxes -How?

Posted on 1998-11-17
3
Medium Priority
?
147 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 10

Accepted Solution

by:
MasseyM earned 450 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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

If you get a (Blue Screen of Death), your system writes a small file called a minidump. Your first step is to make certain your computer is setup to record memory dumps. Right click My Computer, choose properties. Click on the advanced tab, an…
In threads here at EE, each comment has a unique Identifier (ID). It is easy to get the full path for an ID via the right-click context menu. However, we often want to post a short link within a thread rather than the full link. This article shows a…
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

688 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