[Javascript] Checking Radio Boxes with a loop

David Stoltz Dstoltz at SHH.ORG
Mon Feb 16 07:14:29 CST 2009


Hi all,
 
I have 33 questions on a form, each with YES/NO possibilities. I'm
trying to add a button to "check all" yeses - Here's my code:
 
<script>
function qyes(){
 
                for(i=1;i>33;i++)
                                form1.question(i)[0].checked=true;
                
 
}
</script>
 
I know this is not the right way to do this, and of course it doesn't
work....is there some easy way to dynamically say "question1", then
"question2", etc? If I replace the (i) with a number, it works of
course, and this is the part I'm having trouble with. I didn't want to
do this:
 
form1.question1[0].checked=true;
form1.question2[0].checked=true;
form1.question3[0].checked=true;
etc....
 
 
 
Any help?
Thanks!



More information about the Javascript mailing list