Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

A question about listbox!! very hard I think

Status
Not open for further replies.

KryptoS

Programmer
Feb 7, 2001
240
BE
Hi,
here is my problem:
I have 2 listboxs. The first one I fill with values out my database. When I have selected a value in the first listbox the second list box have to fill himself. And also (if possible) the second listbox is 'disabled' and will only be enabled when I have selected a value in the first listbox.

Can someone help me?

greetz
 
Initially you use the listbox's disabled property to disable the second listbox.

In the html code for your first listbox you include a onchange event and call a Javascript function called FillBox2

In this javascript you reopen your asp page with the value of the first listbox as a parameter in the querystring.

In the asp you read this parameter, if it's empty, you haven't selected any item yet and this probably is the first time the page is loaded, but when it has a value you use it to set the value of the first listbox, you enable the second listbox and perform a query using the parameter.

Let's look at some sample code:

Your asp where you fill your listboxes will look somewhat like this:

Code:
...
In the <head> section, include the code below
...

<script language=&quot;JavaScript&quot;>

function FillBox2(listboxobject){
  window.open(&quot;yourasppage&quot; + &quot;?Box1=&quot; + 
  listboxobject.value)
}	
</script>

...
Next: you've just created your recordset to populate the first listbox
...

sValueBox1 = Request.Querystring(&quot;Box1&quot;)

...
Now you will peform a loop to write an <option> tag for each record in the recordset. In this loop you will have to check if the value of the record equals the value in the querystring, if it does, your option tag will look like this:

<option value=34 SELECTED>

...
For the second listbox you will have to add the 'diabled=true' statement only if len(sValueBox1) > 0.
You can also use the variable sValueBox1 in your sql statement

Hope you can make something out of it!

Jordi Reineman
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top