Jump to content

Listing items from combo box


felix_alves

Recommended Posts

hi everyone.
im having some trouble here.
I have a php page with combo box with continents and a list of all countries after it. So far so good, but now i want to: when someone changes the combo box selected item lets say to Europe immediately the list after shows only countries in europe... (the countries and continents all come from a mysql database) how can i do it with php ? do i have to use ajax ?!
Thanks in advance
Link to comment
https://forums.phpfreaks.com/topic/33784-listing-items-from-combo-box/
Share on other sites

here is an idea to get you started.

on your continents drop down, give each option a unique value
<select id = "continents">
<option value ="Europe">Europe</option>
</select>

then for your countries give each dropdown the id of the country it is for but name them all the same and use css to make them all hidden. display: none;

<select id="Euorpe" name ="country">
<option value ="spain">spain</option>
</select>

<select id="North America" name ="country">
<option value ="canada">canada</option>
</select>

now for your js create a function that will listen for a change in your continent dropdown and show the correct country dropdown.

onload = function(){
var cont = document.getElementById('continent');
cont.onchange = function(){
//call the function that will show/hide the country menu
}
}
the situation is slightly different and the continents/countries was just an example but with this last post i think i can make it now, thanks a lot for your time and very important help, if you wanna check the real situation of my problem go to www.actandfilm.com/headshot.php and change the combo box there...you will know perfectly what i need than :) once again thank you!

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.