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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to narrow down values in a drop down based on previos drop down

Status
Not open for further replies.

amir4oracle

Programmer
Nov 3, 2004
46
0
0
CA
Using the select element in html/php/js how can we narrow down the values another drop down.

For eg if we have to select a country in the parent drop down the values in the child drop down should populate automatically lets say state/province.

Do we have to resubmit the page or if we can use ajax. I just need one working eg either ways.

Thanks in advance.
 
there are multiple ways to do it.

1. set the onchange event of the primary select box to submit the form to the server. then test the value of the select box to generate the second select box and send the revised html to the user

2. create multiple secondary selectboxes and set them all to invisible. use some js attached to the primary select box to decide which select box to change the display to visible.

3. create multiple js arrays and store them in the <head> tags. use js in the primary selectbox's onchange event to walk the nodes of the secondary select box and replace the values.

4. you can use variant 1 and make it an ajax interaction. just place the second select box in a span with an id and change the innerHTML with the result of the ajax call (which should return a new select box);

html_quickform (pear.php.net) has a custom element that does this kind of stuff (not using ajax but pure js). you could take a look at the code they use to generate the experience and adapt it.
 
Thank you so much both replies make real sense to me. I am really sorry i forgot to mention that i need to pick data from mysql db.

So its a combination of html/php/js and mysql.

If it's possible to give me one working eg code that would be great.

Regards,
Amir Khan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top