I want to set my dropdown menu from my js. Basically, i want to be able to set the updated drop down value from the js.
my.html
<div class="dropDownList">
<select id="ddpFilter" >
<option value="1">Show 1</option>
<option value="2">Show 2</option>
<option value="3">Show 3</option>
</select>
</div>
my.js
events : {
'change #ddpFilter' : 'Filter'
},
Filter : function(e){
// Set Selected Value of the dropdown
}
});
You should start your function names with a lowercase letter (as per Mr Crockford) and use more descriptive function names.
In order to set the value of a select list, use option[value='x']
syntax. Assuming you'd like to set the second option:
events : {
'change #ddpFilter' : 'filterDdpSelect'
},
filterDdpSelect: function(e){
var selectValue = 2;
$("#ddpFilter option[value='" + selectValue + "']").attr("selected", "selected");
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With