Click to See Complete Forum and Search --> : Checkbox trouble


LTLhawk
April 13th, 2008, 05:04 PM
Hi everyone,

I just signed up to this fourm. This site looks like a great reference for help and I appreciate any help I get. Here is my problem. I have a set of checkboxes grouped in fours and the name of the checkboxes is an array. This part works just fine. What I need to do is if the first checkbox is checked, I want the remaining checkboxes only in that section to automaticly get checked. Here is the code that generated the list of checkboxes:

<? for ($x=0 ; $x < $total ; ++$x){ ?>
<? echo " Group $x<br>"; ?>
<input name="alert_home_cat[<? echo $x ?>]" type="checkbox" id="alert_home_cat[<? echo $x ?>]" />
<input name="alert_email_cat[<? echo $x ?>]" type="checkbox" id="alert_email_cat[<? echo $x ?>]" />
<input name="alert_sms_cat[<? echo $x ?>]" type="checkbox" id="alert_sms_cat[<? echo $x ?>]" />
<input name="alert_rss_cat[<? echo $x ?>]" type="checkbox" id="alert_rss_cat[<? echo $x ?>]" />
<br />
<? } ?>

I know that this can be done with javascript, but because I am using an array for the name of the checkboxes I can not seem to get it to work.
Any help is greatly apprecited.

cherish
April 13th, 2008, 07:52 PM
You can try putting each checkbox group in a table, or div - and since all the checkboxes you want to be checked reside in that "block" you can then have your Javascript code search all "input" tag name, and check all the checkboxes that are there.

I saw this technique in the following site: http://codingforums.com/archive/index.php?t-68342.html

LTLhawk
April 14th, 2008, 04:12 PM
cherish,

that is exactly what I needed.. I like the description they give in that link you posted, it was very informative. Thank you so much..

LTLhawk
April 14th, 2008, 04:50 PM
I just finished implimenting that code example and using it as a guide and it works perfectly. What a great example. THank you thank you...

cherish
April 14th, 2008, 07:59 PM
Don't mention it, LTLawk. I'm glad to find that solution online that helped you - because I also learned something new in the process.

Best regards