[Javascript] Checking Radio Boxes with a loop
David Stoltz
Dstoltz at SHH.ORG
Mon Feb 16 09:29:38 CST 2009
Thanks all! I see there are many solutions! This is the one I went with:
for(i=1;i<34;i++)
eval("form1.question" + i + "[0].checked=true");
Again, thanks for all the quick responses!
-----Original Message-----
From: javascript-bounces at lists.evolt.org
[mailto:javascript-bounces at lists.evolt.org] On Behalf Of Nick Fitzsimons
Sent: Monday, February 16, 2009 9:08 AM
To: JavaScript List
Cc: javascript at lists.evolt.org
Subject: Re: [Javascript] Checking Radio Boxes with a loop
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/
_______________________________________________
Javascript mailing list
Javascript at lists.evolt.org
http://lists.evolt.org/mailman/listinfo/javascript
More information about the Javascript
mailing list