Jump to content

any body could help to populate a drop down menu with a select tag in ajax?


co.ador

Recommended Posts

 

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

 

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

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.

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.