Jump to content

selects box (drop down) that depend on each other


dcay

Recommended Posts

Hi there!

  My question is : can I use php to create 5 drop down boxes that "all" depend of each other ?

  here for example : http://www.e-wohnungsmarkt.at . How can I make all the location select (from country to locals) interact with each other ?  If I chose zip - the selectet values to be the country where the zip is - the distrcit location - city asociacted with that zip...

 

Cristi.

 

How I usually do that is use a bit of javascript on the select tag to submit the form like:

 

<form name='myform'>
<select name='something' onchange='document.forms.myform.submit()'>
<option>Moo</option>
</select>
</form>

 

Then look for the post variable 'something' and if it exists, you can use it to populate the db query that populates the next select element.

 

Make sense?

 

yes, I do eaxactly the same thing but I want to do something else .

 

let's say I have the fields - country - district- city - zip.

for now my script works like you say . if I select a country - in the district field I get the districts in that country.

 

what I want to do is : the selects all have the default string value "All" (option value="0") . I want that when I select zip - country , district , city to be populated with the corresponding values. the country where the zip is from , the district and the city. If I select district - the same thing - the selected values form the other boxes to change to country where the zip is from, the cities& zips in that district.

 

does it make sense? I want that all the selects depend on each other.

Im not quite sure what you mean, are you wanting to do address lookups by zip code? If so there are services that can do that.

 

Or are you wanting to just select the appropriate option that relates? If so then I would look at the vars being posted and compare with the current value in the loop like:

 

$selected = $db_countryID == $countryID ? " selected" : "";

print "<option value='$db_countryID'$selected>$country_name</option>";

 

You might need to use some hidden form fields maybe... not knowing what you are doing exactly.

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.