Link to home
Start Free TrialLog in
Avatar of kiwistag
kiwistagFlag for New Zealand

asked on

Select all checkboxes on a page in a specific section

I have a site where on it is a range of checkboxes. All have different names and values, and are housed in a single table.
I am after a script that will allow me to select all checkboxes in this range without interfering with the others on the same page if possible. So far it's been all on the page or nothing...
Maybe if it could run by the Table name/ID or if I set all checkboxes to have the same ID, it could help...

Code samples/examples would be appreciated.
Avatar of Tom Beck
Tom Beck
Flag of United States of America image

You have not included the jQuery topic area. Is jQuery not an option?

Giving all the checkboxes the same id is NOT an option, but you could give them the same name or the same class and access them that way.

Or, if they all appear in a specific column of a table you can access them like:
var allRows = getElementById('tableId').getElementsByTagName('tr');
for (i = 0; i < allRows.length; i++) {
    var cells = allRows[i].getElementsByTagName('td');
   //cells[number] would be the cell with the checkbox in it, set it to checked
}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Tom Beck
Tom Beck
Flag of United States of America 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
Avatar of kiwistag

ASKER

Sorry, forgot to include jQuery. Yes! That worked perfectly - thank you :)
You're welcome. Thanks for the points.