Chase Price
Chase Price

Reputation: 69

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);
      });
    });

Upvotes: 0

Views: 84

Answers (1)

ihpar
ihpar

Reputation: 676

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>

Upvotes: 1

Related Questions