Solved

Select all checkboxes on a page in a specific section

Posted on 2014-01-04
4
256 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

Question has a verified solution.

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

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In this Micro Tutorial viewers will learn how to create navigation buttons that change on rollover, using CSS (Continuation of the CSS Image Sprite tutorial) Create a parent ID for all the list items       - Specify position: absolute and display: block…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).
Suggested Courses

617 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