If it is not disabled,

I add the numbers entered in some inputs and get the total. The overall script works, however now I do not want to include the inputs that will be taken into account if they are disabled. I think I need to use: not (: disabled), but not sure how to put it in my script correctly?

This is a script that is considered:

$('.observationPositive').each(function(){
    countP++;
    sumP += Number($(this).val());
});

How can I say only the account, if not disconnected? (mistakenly encoded example)

$('.observationPositive').each(function(){
    countP++;
    sumP += Number($(this:not(:disabled)).val());
});
+5
source share
3 answers

Sort through only those that are not disabled:

$('.observationPositive:not(:disabled)').each(function() {
   // increment count
});
+13
source

Your selector should be a string:

 $(this).is(":not(:disabled)");

. val jQuery, , undefined, undefined , NaN.

sumP += $(this).is(":disabled") ? 0 : Number($(this).val());    

Jivings .

+8

Add restrictions to the main selector:

$('.observationPositive:not(:disabled)').each(function(){
    countP++;
    sumP += Number($(this).val());
});
+1
source

All Articles