Reply
Toggle Check/Uncheck All with Checkbox Array
Old 11-29-2008, 01:23 PM Toggle Check/Uncheck All with Checkbox Array
Galaxian's Avatar
Dingleberry!

Posts: 695
Name: Rich
Location: United Kingdom
How can I toggle between checking and unchecking all the checkboxes in an array.. for example.. name="checkbox[]"

I have this so far

Code:
function toggleCheck(fn) {
if(fcheck == 1) {
for (i = 0; i < fn.length; i++) {
fn.checked = false;
}
fcheck = 0;
} else {
for (i = 0; i < fn.length; i++) {
fn.checked = true;
}
fcheck = 1;
}
}
__________________
Galaxian is offline
Reply With Quote
View Public Profile Visit Galaxian's homepage!
 
When You Register, These Ads Go Away!
Old 11-29-2008, 01:40 PM Re: Toggle Check/Uncheck All with Checkbox Array
tripy's Avatar
Do not try this at home!

Posts: 2,818
Name: Thierry
Location: Latitude 46.79057 :: Longitude 7.119377
Code:
aryChk=document.getElementsByTagName('input');
for(cptChk=0;cptChk<aryChk.length;cptChk++){
  elem=aryChk[cptChk]
  if( (elem.type.lower()=='checkbox') && (elem.checked==false) ){
    elem.checked=true;
  }
}
This should do nicely...
__________________
Trust me, I know what's good for you...

tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 11-29-2008, 01:47 PM Re: Toggle Check/Uncheck All with Checkbox Array
Galaxian's Avatar
Dingleberry!

Posts: 695
Name: Rich
Location: United Kingdom
That checks all the checkboxes on the page right?

I just want a function where you just put the array's name in and it toggles the check.. the checkboxes names are arrays though e.g name[]
__________________
Galaxian is offline
Reply With Quote
View Public Profile Visit Galaxian's homepage!
 
Old 11-29-2008, 03:33 PM Re: Toggle Check/Uncheck All with Checkbox Array
tripy's Avatar
Do not try this at home!

Posts: 2,818
Name: Thierry
Location: Latitude 46.79057 :: Longitude 7.119377
Then add an check condition in the if...
__________________
Trust me, I know what's good for you...

tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Reply     « Reply to Toggle Check/Uncheck All with Checkbox Array
 

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 



Page generated in 0.08809 seconds with 12 queries