Solved

Select all checkboxes on a page in a specific section

Posted on 2014-01-04
4
251 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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
In this tutorial viewers will learn how to embed Flash content in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <object> tag to embed Flash content.: To specify that the object is Flash content, d…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

746 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

14 Experts available now in Live!

Get 1:1 Help Now