Using jQuery to change the value of one dropdown from another

I have two drop-down lists, and I would like to make it so that when someone selects, for example, the value 2 from dropdown1, dropdown2 automatically changes to the value 2. Is this possible with jquery?

<select id="dropdown1">
 <option value="1">Item1</option>
 <option value="2">Item2</option>
 <option value="3">Item3</option>
</select>

<select id="dropdown2">
 <option value="1">Item1</option>
 <option value="2">Item2</option>
 <option value="3">Item3</option>
</select>
+3
source share
1 answer

This should do it:

$("#dropdwon1").change(function(){
    $("#dropdwon2").val($(this).val());
});

working version here: http://jsfiddle.net/xkT3U/

+8
source

Source: https://habr.com/ru/post/1781277/


All Articles