Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



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: 825
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;
}
}
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
Galaxian is offline
Reply With Quote
View Public Profile Visit Galaxian's homepage!
 
 
Register now for full access!
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,621
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 offline
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: 825
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[]
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
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,621
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 offline
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.13205 seconds with 12 queries