fuey fuey - 8 months ago 13
Javascript Question

Detect any select that a user changes the value of

I have 20 selects on a page and I need to detect when a user sets any one of them to a value > 0 (the default value for each one is 0). They are all of class "numSel" so I'm trying to make this code work:

if($('.numSel').val() > 0){
$("#submit").prop('disabled', false);

But this only works on the first select on the page. If I choose one of the other selects the submit button remains disabled.

Any ideas?


If the code is within a .change() or .each() block, you can use this to reference the <select> that changed.

$('.numSel').change(function() {
    if ($(this).val() > 0)
        $("#submit").prop('disabled', false);
}).change(); // run the block here to detect the initial values