Reputation: 5327
How can i check if there any change occurred for dropdown box using jquery?
<select id="bonus">
<option value="1">-$5000</option>
<option value="2">-$2500</option>
<option value="3">$0</option>
<option value="4" selected="selected">$1</option>
<option value="5">We really appreciate your work</option>
</select>
Initial selected value is 4. I have to recognize whether any update/change occurred for the tag Same i have to check for multiselect dropdown also.
Upvotes: 1
Views: 1801
Reputation: 5545
The .change event in jQuery handles both single select and multi select for dropdowns.
here is the code for your select
$(function(){
$("#bonus").change(function(){
alert('changed');
});
});
Hope this helps
Upvotes: 1
Reputation: 13801
Try something like this:
$("select").change(function () {
var txt = $(this).val();
$(this).next('span.out').text(txt);
}).trigger('change');
OR
$("select").each(function(){
var select = $(this),
out = select.next();
select.change(function () {
out.text(select.val());
});
}).trigger('change');
Upvotes: 1
Reputation: 1404
try doing this in document ready
$( "#bonus" ).change(function() {
alert( "Handler for .change() called." );
});
Reference : http://api.jquery.com/change/
Upvotes: 2