简体   繁体   中英

When one dropdown is selected then the same option is selected in a different dropdown

I have two dropdowns and I want to make it whenever someone selects something in one dropdown the same thing is selected in the other dropdown. I can't get it to work when I select an option in the first dropdown then it doesn't select the same option in the other dropdown. Here's the formula

$( function() {
    $("input[name='FirstFlangeTypeDrop']").on("change", function(e) {
         var newValue = e.target.value;
         $("input[name='SecondFlangeTypeDrop'][value='" + newValue + "']").prop("selected", true);
      });
    });

Your question is a bit unclear to me. But I think this is what you are looking for.

 $(function() { $("select[name='FirstFlangeTypeDrop']").on("change", function(e) { var newValue = $(this).val(); // get selected value $("select[name='SecondFlangeTypeDrop']").val(newValue); // set selected value }); }); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <select name="FirstFlangeTypeDrop"> <option value="1">option 1</option> <option value="2">option 2</option> </select> <select name="SecondFlangeTypeDrop"> <option value="1">option 1</option> <option value="2">option 2</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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM