Jump to content

displaying DB content w/ select menu


webguync

Recommended Posts

I have a select menu of states that uses Javascript to autopopulate another select form depending on which state is choses will display cities within that state. I know want to display property results from a MySQL DB so for instance when someone chooses California and Los Angeles and hits submit the property results for that particular city will display. I have city set up as a field in the database and just need some help with the PHP to make this happen.

 

thanks in advance.

Link to comment
Share on other sites

I will just show the code for one state since 50 of them produced a lot of code

 

<table>
<tr>
<form name="classic">
  <select name="countries" size="4" onChange="updatecities(this.selectedIndex)" style="width: 150px">
  <option selected>Select A State and City</option>
  <option value="AL">AL</option>
ption>

  </select>

</td>
<td>
  <select name="cities" size="4" style="width: 150px" onClick="alert(this.options[this.options.selectedIndex].value)">
  </select>
  </form>

<script type="text/javascript">

  var countrieslist=document.classic.countries
  var citieslist=document.classic.cities

  var cities=new Array()
  cities[0]=[""]
  cities[1]=["Auburn|auburnvalue", 
  function updatecities(selectedcitygroup){
  citieslist.options.length=0
  if (selectedcitygroup>0){
  for (i=0; i<cities[selectedcitygroup].length; i++)
  citieslist.options[citieslist.options.length]=new Option(cities[selectedcitygroup][i].split("|")[0], cities[selectedcitygroup][i].split("|")[1])
  }
  }

</script>
</td>
</tr>
</table>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.