user1148875 user1148875 - 6 months ago 30
Javascript Question

How can get length on checked checkbox array javascript

<form name='form1' >
<input type=checkbox name='cbox[]' />

var checkbox = document.getElementsByName('ckbox[]')
var ln = checkbox.length

How can I count only the checked checkboxes with javascript or jQuery?


Doing it with jQuery would shorten the code and make it more readable and maintable. Use attribute selector with :checked selector

Live Demo