Reputation: 125
in my jsp form i have one checkbox Array in my form(jsp and struts).i want to know the length of checkbox Array in java script. ex: <input:checkbox property="chkbox[]"/>
. in javascript i am calling document.form[0].chkbox[].value.length
but it showing javaScript error null or undefined .
Upvotes: 0
Views: 12154
Reputation: 3793
var checkbox = document.getElementsByName('a_checkbox')
var ln = checkbox.length
line 1 get all the active checked boxes line 2 in the length of that array
Upvotes: 3
Reputation: 30187
if this the html
<form name='form1' >
<input type=checkbox name='cbox' />
<input type=checkbox name='cbox' />
<input type=checkbox name='cbox' />
<input type=checkbox name='cbox' />
<input type=checkbox name='cbox' />
<input type=checkbox name='cbox' />
<input type=checkbox name='cbox' />
</form>
javascript for that length would be
alert(document.form1.cbox.length);
or you can also use.
document.getElementsByName('cbox').length
Upvotes: 1