co.ador Posted June 27, 2010 Share Posted June 27, 2010 <td> <div align="left"> <select name="city2" id="label"> <option value="1">La Romana </option> <option value="2">Rofetola</option> </select> </div> </td> <td bordercolor="#000000"> <div align="right"> <label for="neighborhood">Neighborhood:</label> </div> </td> <td> <div align="left"> <select name="neighborhood" id="neighborhood"> <option>Villa Verde</option> <option>Caleta</option> <option>La Aviacion </option> <option>Ensanche la Oz</option> <option>Papagayo</option> <option>Vista Norte</option> <option>Buena Vista</option> <option> Norte spain</option> <option> Norte</option> <option>Calofeta</option> </select> </div> </td> In the code above there is an Select statment that lists two cities and each city will have different neighborhoods now when select city value #1 I want the first five neigborhoods to appear in the select list for neighborhoods and for the second city value #2 the rest of the neighborhoods... does anybody has an idea or tutorial where I can implement that dynamic content and what would be best to use php or javascript. Quote Link to comment https://forums.phpfreaks.com/topic/205969-any-body-could-help-to-populate-a-drop-down-menu-with-a-select-tag-in-ajax/ Share on other sites More sharing options...
F1Fan Posted June 28, 2010 Share Posted June 28, 2010 Using Ajax would give you the most flexibility and would be best if you plan on pulling this data from a database, but if you will only ever have those two cities with those neighborhoods, just do it in JavaScript. Another option would be to write your JavaScript with PHP when the page initially loads. Here's a JS tutorial on adding and removing options from selects: http://www.javascriptkit.com/jsref/select.shtml Quote Link to comment https://forums.phpfreaks.com/topic/205969-any-body-could-help-to-populate-a-drop-down-menu-with-a-select-tag-in-ajax/#findComment-1078268 Share on other sites More sharing options...
co.ador Posted June 29, 2010 Author Share Posted June 29, 2010 I thinking to have three countries and then each country will have different cities and each city different neighborhood that the sequences. Quote Link to comment https://forums.phpfreaks.com/topic/205969-any-body-could-help-to-populate-a-drop-down-menu-with-a-select-tag-in-ajax/#findComment-1078534 Share on other sites More sharing options...
F1Fan Posted June 29, 2010 Share Posted June 29, 2010 Yeah, if I were you I would write a few JS functions with PHP, populating the country, city, and neighborhood lists. Then have an onchange event on the country that populates the city, and one on the cities that populates the neighborhood. Quote Link to comment https://forums.phpfreaks.com/topic/205969-any-body-could-help-to-populate-a-drop-down-menu-with-a-select-tag-in-ajax/#findComment-1078706 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.