Click to See Complete Forum and Search --> : Dynamic dropdown boxes


TimO
09-15-2003, 11:18 AM
I am looking for help dynamically loading dropdown boxes. There are a couple scripts on this site that use the selection from the first dropdown to load the second box. All of these hard-code the options though. Is there a way to load the second box from a table where the query would use a variable which is the selection from the first box?

Jona
09-15-2003, 11:49 AM
If you mean pull data from a database without reloading the page, you'll have to do it in Java or Flash.

[J]ona

TimO
09-15-2003, 11:53 AM
Thanks for the response. The script titled DROPDOWN BOX POPULATION would be ideal if I didn't have to hard-code the values.

Tim

Jona
09-15-2003, 11:54 AM
Originally posted by TimO
Thanks for the response. The script titled DROPDOWN BOX POPULATION would be ideal if I didn't have to hard-code the values.

You lost me there, my friend. Could you please provide the URL to the script of which you are speaking?

[J]ona

TimO
09-15-2003, 11:58 AM
Sorry Jona. The script that is basically what I want is at http://javascript.internet.com/forms/dropdown-box-population.html.

Jona
09-15-2003, 12:00 PM
Hmm, I see. Are you trying to populate the fields by pulling data from the server or from a database? If so, I'd suggest setting the JavaScript variable values according to what is taken from the server (kind of like a pre-loading concept).

[J]ona

TimO
09-15-2003, 12:02 PM
Loading the first dropdown is no problem. The issue is filling the second dropdown from the database after a selection is made from the first dropdown.

Jona
09-15-2003, 12:19 PM
Originally posted by TimO
Loading the first dropdown is no problem. The issue is filling the second dropdown from the database after a selection is made from the first dropdown.

I see, then you must be using a database to pull your information. Why not just fill in the possible values of the second dropdown menu in the JavaScript variables onload? Example in PHP (it would be a 2D array, as the code already probably uses):


var array_01 = new Array(new Array("<?php echo($variable_gotten_from_database); ?>"), new Array("<?php echo($variable2_gotten_from_database); ?>"));


[J]ona

TimO
09-15-2003, 12:22 PM
I am new at HTML and have never touched a javascript but will give that a try.

Thanks again for the help.

Jona
09-15-2003, 12:24 PM
Originally posted by TimO
I am new at HTML and have never touched a javascript but will give that a try.

Thanks again for the help.

Glad to be of assistance! Tell me how it works out, if it does. (Oh yes, I know you will be back with another question.) ;)

[J]ona