How to Create a filter between two dropdowns using jquery

Asked

Viewed 39 times

0

I have two dropdowns (state and cities)

in select "status"

I have the options of two states ex:

<select name="state">
         <option value="NY">New York</option>
         <option value="LA">Los Angeles</option>
 </select>

<select name="city">
         <option value="NY">Norwich</option>
         <option value="NY">Younkers </option>

         <option value="LA">Beverly Hills </option>
         <option value="LA">Santa Monica</option>
 </select>

what I need is to filter via jquery the dropdown "city" using the "state" Value ie when I select in the State the "New York " automatically in the dropdown "city" should only appear the cities that have the NY value..

please....

1 answer

2

It would be nice if you sent a request for your application to return the second list in the first list change event. Do so:

$("#PRIMEIRO_COMBOBOX").on('change', function(){
       $.ajax({
         type: method,
         url: url,
         data: data,
         success: function(response) {
             //Aqui popula seu segundo combobox com o retorno da aplicação  
         } 
       }); 
   });

Any doubt I’m available.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.