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
https://forums.phpfreaks.com/topic/103208-displaying-db-content-w-select-menu/
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>

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.