Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
106
rated 0 times [  112] [ 6]  / answers: 1 / hits: 90124  / 11 Years ago, wed, february 27, 2013, 12:00:00
<form name='form1' >
<input type=checkbox name='cbox[]' />
</form>

<script>
var checkbox = document.getElementsByName('ckbox[]')
var ln = checkbox.length
alert(ln)
</script>


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


More From » jquery

 Answers
27

Doing it with jQuery would shorten the code and make it more readable, maintainable and easier to understand. Use attribute selector with :checked selector



Live Demo



$('[name=cbox[]]:checked').length

[#79966] Tuesday, February 26, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
colby

Total Points: 311
Total Questions: 102
Total Answers: 102

Location: Taiwan
Member since Mon, Sep 6, 2021
3 Years ago
;