I want to change the selected option of select menu when another select menus changed but i can't. This is my code:
$('#select_menu_1').on('change',function(){
$('#select_menu_2').val(2).trigger('change');
});
This code doesn't work and my problem is select_menu_2
doesn't changing when i change the select_menu_1
. How can i do this work?
Use this code
$("#dropdown1").change(function() { var value = $("option:selected", this).val(); $("#dropdown2 > option[value=" + value + "]").attr("selected", true); })
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <select id="dropdown1"> <option value="Option-1">Option-1</option> <option value="Option-2">Option-2</option> <option value="Option-3">Option-3</option> </select> <select id="dropdown2"> <option value="Option-1">Option-1</option> <option value="Option-2">Option-2</option> <option value="Option-3">Option-3</option> </select>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.