Reputation: 1045
I have a dropdown list:
<select size="1" name="filter"id="priority_filter" onchange="filter_user_trainings();">
<option value="all">All</option>
<option value="optional">Optional</option>
<option value="mandatory">Mandatory</option>
<option value="essential">Essential</option>
<option value="custom">Custom</option>
</select>
In a function
I call these:
if(db==0 || db==1 ||db==2)
{
$("#priority_filter").val('custom');
}
I want to fire the select
onchange
function when the jQuery switches the value. How can I do this? The code above does not work.
Upvotes: 9
Views: 34453
Reputation: 148110
You can call change()
on select
to first or .trigger("change");
if(db==0 || db==1 ||db==2)
{
$("#priority_filter").val('custom');
$("#priority_filter").change();
}
OR
if(db==0 || db==1 ||db==2)
{
$("#priority_filter").val('custom').change();
}
Upvotes: 28
Reputation: 4656
$(document).ready(function(){
..code..
$('#priority_filter').on('change', function(){
..do your stuff..
}
..code..
});
Upvotes: 3
Reputation: 17366
Try this: On load
$("#priority_filter").change(function(){
var val = $("#priority_filter").val();
//alert(val);
//your code
});
Demo Here: http://jsfiddle.net/j8DPN/
Upvotes: 0