469,270 Members | 1,170 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,270 developers. It's quick & easy.

Select/Deselect All With Checkbox

Hi guys,

I'm having some trouble writing code for this purpose of select/deselect all function.

I do not want to use the form "name" because i want ensure that it is html strict. Also my form is being tracked so all input fields have a different name. I want to be able to do this by assigning each input checkbox field with an "id" tag. Any suggestions?
Jul 25 '07 #1
3 4284
iam_clint
1,208 Expert 1GB
how about this for example
Expand|Select|Wrap|Line Numbers
  1. function SelectAll(val) {
  2.   var objects = document.getElementsByTagName("input"); //all input objects
  3.   for (i=0; i<objects.length;i++) { //start for loop
  4.     if (objects[i].getAttribute("type")=="checkbox") { objects[i].checked = val; } //checkbox found set its checked attribute
  5.   }
  6. }
  7.  
Then call the function like this

Expand|Select|Wrap|Line Numbers
  1. <input type="button" onclick="SelectAll(true);" value="Select All">
  2. <input type="button" onclick="SelectAll(false);" value="Deselect All">
  3.  
Jul 25 '07 #2
Thanks for this...now the problem with this is that I am actually using a "checkbox" itself to deselect all the other checkboxes. It works, but the checkbox I'm using I want to be able to be checked. Does that make sense?



how about this for example
Expand|Select|Wrap|Line Numbers
  1. function SelectAll(val) {
  2.   var objects = document.getElementsByTagName("input"); //all input objects
  3.   for (i=0; i<objects.length;i++) { //start for loop
  4.     if (objects[i].getAttribute("type")=="checkbox") { objects[i].checked = val; } //checkbox found set its checked attribute
  5.   }
  6. }
  7.  
Then call the function like this

Expand|Select|Wrap|Line Numbers
  1. <input type="button" onclick="SelectAll(true);" value="Select All">
  2. <input type="button" onclick="SelectAll(false);" value="Deselect All">
  3.  
Jul 25 '07 #3
vee10
141 100+
Thanks for this...now the problem with this is that I am actually using a "checkbox" itself to deselect all the other checkboxes. It works, but the checkbox I'm using I want to be able to be checked. Does that make sense?
hi ,

This may solve ur problem

Expand|Select|Wrap|Line Numbers
  1. function SelectAll() 
  2.     {
  3.       var objects = document.getElementsByTagName("input"); //all input objects
  4.      for (i=0; i<objects.length;i++) { //start for loop
  5.      debugger
  6.  
  7.      if (objects[i].getAttribute("type")=="checkbox")
  8.       { 
  9.       objects[i].checked = document.getElementById("SelOrDelsel").checked; } //checkbox found set its checked attribute
  10.       }
  11. }
  12.  
and the check for which u need to check or deselct the other checkboxes
Expand|Select|Wrap|Line Numbers
  1.   <input type="checkbox" id="SelOrDelsel" onclick="SelectAll();" value="Select All" />Select / DeSelect
  2.  
Jul 26 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

3 posts views Thread by Notorious | last post: by
5 posts views Thread by _andrea.l | last post: by
5 posts views Thread by colleen1980 | last post: by
1 post views Thread by CARIGAR | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.