[Javascript] Checking Radio Boxes with a loop

Nick Fitzsimons nick at nickfitz.co.uk
Mon Feb 16 08:07:38 CST 2009


Hi,

Try:

for (i = 1; i < 33; i++) {
    form1['question' + i][0].checked = true;
}

(I haven't tested this, but it should work.)

Regards,

Nick.

On Mon, February 16, 2009 1:14 pm, David Stoltz wrote:
> 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!
> _______________________________________________
> Javascript mailing list
> Javascript at lists.evolt.org
> http://lists.evolt.org/mailman/listinfo/javascript
>


-- 
Nick Fitzsimons
http://www.nickfitz.co.uk/





More information about the Javascript mailing list