Solved

Dynamic listboxes -How?

Posted on 1998-11-17
3
143 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 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

Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
AWK: Am I duplicating the comma delimiter in this code? 5 39
powershell automatic variable for results 21 39
BatchFile-Disk Detection 23 53
Google Chrome: Debugging AJAX call 6 33
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…
I hope you'll find this tutorial useful and interesting. So let's try to extend Tcl with a new package.  For anyone more deeply interested please check out the book "Practical Programming in Tcl and Tk". It's really one of the best written books abo…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

739 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