admin管理员组

文章数量:1333710

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 .

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 .

Share Improve this question edited Dec 1, 2011 at 11:08 Sai Kalyan Kumar Akshinthala 11.8k8 gold badges45 silver badges68 bronze badges asked Dec 1, 2011 at 11:03 java_devjava_dev 1253 gold badges3 silver badges13 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 3
    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

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

本文标签: javascriptHow can get CheckBox Array length in java scriptStack Overflow