Reputation: 1210
My html is
<select name="one_day_per_month" id="one_day_per_month" style="width: 200px">
<option value="false" selected>No</option>
<option value="true">Yes</option>
</select>
The page is wrapped with
$( document ).ready(function() {...}
I can change the value by using
$("#one_day_per_month").val("true")
The value is updated, but the dropdown list does not change in the browser does not change. What am I doing wrong?
Upvotes: 0
Views: 1004
Reputation: 11859
Try this call trigger with change to achieve your requirement.
$( document ).ready(function() {
$("#one_day_per_month").val("true").trigger("change");
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<select name="one_day_per_month" id="one_day_per_month" style="width: 200px">
<option value="false" selected>No</option>
<option value="true">Yes</option>
</select>
Upvotes: 1
Reputation: 17381
Your code is probably running before the HTML tags for your select element is loaded. You have two ways to fix it:
Upvotes: 0