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

Posts: 728
Name: Rich
Location: United Kingdom
Trades: 0
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, 02:40 PM Re: Toggle Check/Uncheck All with Checkbox Array
tripy's Avatar
Do not try this at home!

Posts: 3,176
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
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...
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is online now
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 11-29-2008, 02:47 PM Re: Toggle Check/Uncheck All with Checkbox Array
Galaxian's Avatar
Dingleberry!

Posts: 728
Name: Rich
Location: United Kingdom
Trades: 0
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, 04:33 PM Re: Toggle Check/Uncheck All with Checkbox Array
tripy's Avatar
Do not try this at home!

Posts: 3,176
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
Then add an check condition in the if...
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is online now
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Reply     « Reply to Toggle Check/Uncheck All with Checkbox Array
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

BB 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.12813 seconds with 13 queries