Checkbox enabled count

Asked

Viewed 36 times

1

That code counts how many checkbox were marked.
How can I make sure he doesn’t count checkbox disabled

<script type='text/javascript'>//<![CDATA[
window.onload=function(){
var contador = function() {
var n = $( "input:checked" ).length;
$("#checkcount").text( n + (n === 1 ? " é" : " são") + " selecionados" );
};
contador(); 
$( "input[type=checkbox]" ).on( "click", contador );
}//]]> 
</script>


<input type="checkbox" name="check1" disabled value="1">
<input type="checkbox" name="check1" disabled value="2">
<input type="checkbox" name="check1" value="3">
<input type="checkbox" name="check1" value="4">
<input type="checkbox" name="check1" value="5">    
<div id="checkcount"></div>

1 answer

2


Instead

var n = $( "input:checked" ).length;

Put this on:

var n = $( "input:enabled:checked" ).length;

Browser other questions tagged

You are not signed in. Login or sign up in order to post.