Solved

Select all checkboxes on a page in a specific section

Posted on 2014-01-04
4
252 Views
Last Modified: 2014-01-04
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.
0
Comment
Question by:kiwistag
  • 3
4 Comments
 
LVL 38

Expert Comment

by:Tom Beck
ID: 39756059
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

0
 
LVL 38

Accepted Solution

by:
Tom Beck earned 375 total points
ID: 39756140
Of course with jQuery it's simple, regardless of where the checkboxes appear in the table or on the page for that matter. Just give them all the same class name.

http://jsfiddle.net/tTF3k/2/
0
 
LVL 6

Author Comment

by:kiwistag
ID: 39756522
Sorry, forgot to include jQuery. Yes! That worked perfectly - thank you :)
0
 
LVL 38

Expert Comment

by:Tom Beck
ID: 39756530
You're welcome. Thanks for the points.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

914 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now