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.

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

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.