Current location: Hot Scripts Forums » General Web Coding » JavaScript » checkbox length


checkbox length

Reply
  #1 (permalink)  
Old 02-24-04, 01:37 AM
sCruFyGal sCruFyGal is offline
New Member
 
Join Date: Feb 2004
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
checkbox length

hello, i use javascript to check-all and encheck-all the checkboxes, but when there is more than one checkboxes, it works, but if there is only one checkbox, it wont work, and below is the coding:

function checkall(ckb)
{


alert (ckb.length)

for (i =0; i<ckb.length;i++)
if(ckb[i].type == "checkbox")
{
if(!ckb[i].checked == true)
{
ckb[i].checked = true;
}

}

}
when there is only one checkbox, the ckb.length is undefined, anyone can help me?? thanks a lot
Reply With Quote
  #2 (permalink)  
Old 02-24-04, 03:22 AM
jimcart jimcart is offline
Newbie Coder
 
Join Date: Feb 2004
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Hi,

Not sure if what I have added will work
but something like it should.

If you give me a copy of a html file with the script being called I am sure I can fix your problem.

Regards,
Jim -- jimcart@jimcart.com



Quote:
Originally Posted by sCruFyGal
hello, i use javascript to check-all and encheck-all the checkboxes, but when there is more than one checkboxes, it works, but if there is only one checkbox, it wont work, and below is the coding:

function checkall(ckb)
{


alert (ckb.length)

if (ckb.length) {
for (i =0; i<ckb.length;i++)
if(ckb[i].type == "checkbox")
{
if(!ckb[i].checked == true)
{
ckb[i].checked = true;
}

}

}
}
when there is only one checkbox, the ckb.length is undefined, anyone can help me?? thanks a lot
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
lock form fields using checkbox jonathen JavaScript 5 02-04-05 03:35 PM
How to enabled or disabled input text using a checkbox Han84 HTML/XHTML/XML 1 10-13-03 08:46 AM
dynamic web pages using the checkbox component oasp PHP 6 08-12-03 02:54 PM
dynamic web pages using the checkbox component oasp Script Requests 1 08-11-03 09:07 AM
Using CDONTS to email Checkbox results AkaMadDiSk ASP 1 07-23-03 05:32 PM


All times are GMT -5. The time now is 02:10 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.