Checkboxes - how to iterate

Y

Yitzak

Hi - a newbie question.

I have a asp page with a form with several checkboxes..

<INPUT TYPE=CHECKBOX NAME="CHK1" VALUE=C1B999>
<INPUT TYPE=CHECKBOX NAME="CHK1" VALUE=C1B800>

All checkboxes have the same name but ID values change.

How do I reference them in Javascript?

I would like to do something like

for i=0;i<thisform.chk1.count;i++
{
if thisform.chk1. = checked then return true;
}

Thanks...
 
D

David Dorward

<INPUT TYPE=CHECKBOX NAME="CHK1" VALUE=C1B999>
<INPUT TYPE=CHECKBOX NAME="CHK1" VALUE=C1B800>
How do I reference them in Javascript?

var cbs = document.forms['myform'].elements['CHK1'];
for (var i = 0; i < cbs.length; i++) {
if (cbs.checked) {
return true;
}
}
return false;
 
Y

Yitzak

var cbs = document.forms['myform'].elements['CHK1'];
for (var i = 0; i < cbs.length; i++) {
if (cbs.checked) {
return true;
}}

return false;


Thanks David - much appreciated..
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,175
Latest member
Vinay Kumar_ Nevatia
Top