I would like to see if a particular drop down menu item has been selected or deselected.
I have tried
jQuery("#dropdownID option[value='selectionKey']").change(function() {
if (jQuery("#dropdownID option[value='selectionKey']").attr('selected', 'selected'))
DoSomething();
else DoSomethingElse();
});
and
jQuery("#dropdownID").change(function() {
if (jQuery("#dropdownID option[value='selectionKey']").attr('selected', 'selected'))
DoSomething();
else DoSomethingElse();
});
but neither block is triggered by changing the selection in the drop down menu. That is, it never gets to the if statement.
You can try something like this in jquery versions less than 1.7:
$("#dropdownID").live('change', function() {
if ($(this).val() == 'selectionKey'){
DoSomething();
} else {
DoSomethingElse();
}
});
You can try something like this in jquery versions greater than 1.7:
$("#dropdownID").on('change', function() {
if ($(this).val() == 'selectionKey'){
DoSomething();
} else {
DoSomethingElse();
}
});
Try these:
jQuery("#dropdownID").change(function() {
if (jQuery("#dropdownID option[value=selectionKey]").attr('selected', 'selected')) {
DoSomething();
}
else {
DoSomethingElse();
}
});
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