How to create a filter between two dropdowns using jquery

0

I have two dropdowns (state and cities)

do not select "status"

I have the options of two ex states:

<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 value of "state" ie when I select in the State "New York" automatically in the dropdown "city" should only appear the cities that have the value NY ..

Please ...

    
asked by anonymous 11.10.2018 / 11:55

1 answer

2

It would be nice to send a request for your application to return the second list in the event of change of the first list. Here's how:

$("#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 questions are available.

    
11.10.2018 / 12:47