Solved

Dynamic listboxes -How?

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Batch, VBS, and scripts in general are incredibly useful for repetitive tasks.  Some tasks can take a while to complete and it can be annoying to check back only to discover that your script finished 5 minutes ago.  Some scripts may complete nearly …
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
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 this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

760 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

21 Experts available now in Live!

Get 1:1 Help Now