Link to home
Start Free TrialLog in
Avatar of Bruce Gust
Bruce GustFlag for United States of America

asked on

How can I implement a "Select All" with this configuration...?

Here's my HTML:

<input type="checkbox" value="13" name="chkbox_13">
<input type="checkbox" value="14" name="chkbox_14">
<input type="checkbox" value="25" name="chkbox_25">
<input type="checkbox" value="43" name="chkbox_43">

It's at PHP script that's looping through all of the students in the database. Their ID is both the value and the latter portion of the "chkbox_
 dynamic.

I want to incorporate a "Select All." I was drawn to this:

<script language="JavaScript">
function toggle(source) {
  checkboxes = document.getElementsByName('foo');
  for each(var checkbox in checkboxes)
    checkbox.checked = source.checked;
}
</script>

<input type="checkbox" onClick="toggle(this)" /> Toggle All<br/>

But in light of the way I'm naming my checkboxes, I figured I needed some help.

Thoughts?
SOLUTION
Avatar of hielo
hielo
Flag of Wallis and Futuna image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Bruce Gust

ASKER

I need a select all. I'm just now realizing that there is a difference and I apologize. I want a checkbox at the top of my list that when checked, all of the boxes below are automatically checked.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I changed my naming conventions and learned a little bit about how to name an input field in a way the system understands to be an array.

Sweet!

Thanks!