checkbox script.

This is a discussion on "checkbox script." within the JavaScript Forum section. This forum, and the thread "checkbox script. are both part of the Program Your Website category.



Go Back   Webforumz.com > Main Forums > Program Your Website > JavaScript Forum

Notices


Reply
 
LinkBack Thread Tools
  #1 (permalink)  
Old Jan 17th, 2008, 21:58
New Member
Join Date: Jan 2008
Location: sydney
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
checkbox script.

Hi everyone,

I am new to the fun world of javascript and am having a problem with this little script... perhaps one of you guys can help...

what I am trying to achieve is to have a series of checkboxes that display options to my user. they are

option 1
option 2
option 3
option 4

select all.


the goal here is when a user clicks the select all box it clears all the options and disables them except the select all button. if the user decides to select from the other options, they can but only after they have de-selected the select all checkbox.

what i have so far is below...
HTML: Select all
<SCRIPT LANGUAGE="JavaScript">

function Check(chk)
{
if(document.myform.AllRecipients.checked==true){
for (i = 0; i < chk.length; i++)
chk[i].checked = false ;


}else{

for (i = 0; i < chk.length; i++)
chk[i].checked = false ;
}
}
</script>


<form id="myForm" name="myform" action="" method="post" enctype="multipart/form-data">

<input enabled  type="checkbox" name="Recipients" onClick="agreesubmit(this);" value="1" /><font class="FormLabel"></font>

<input type="checkbox" name="AllRecipients" value="0" onClick="Check(document.myform.Recipients); agreesubmit(this);" />

</form>

Last edited by Rakuli; Jan 18th, 2008 at 04:32. Reason: Added some [html][/html] BBC tags
Reply With Quote

  #2 (permalink)  
Old Jan 17th, 2008, 22:05
Reputable Member
Join Date: Nov 2007
Location: India
Posts: 150
Blog Entries: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Re: checkbox script.

Found similar one here. See if you can compare and induce.
http://www.codecoffee.com/articles/9tips.html
Last Blog Entry: Cross browser nuisance (Feb 11th, 2008)
Reply With Quote
  #3 (permalink)  
Old Jan 18th, 2008, 04:42
Rakuli's Avatar
SuperMember

SuperMember
Join Date: Sep 2007
Location: Australia
Age: 24
Posts: 956
Blog Entries: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Re: checkbox script.

G'day mate..

You can change the function to something like that below... commented to help you understand

Code: Select all
function Check(chk)
{
    // first thing we'll do is get the elements from the form
    var formElements = chk.getElementsByTagName('input');
    var nm = formElements.length; // count them

   // now, are we enabling or disabling.. If the 'AllRecipients' box is checked then we must be disabling and vice versa

   var ea = chk.AllRecipients.checked ? false : true; 
// now cycle through the elements and we'll do some checking to see if it's a 
// checkbox and whether to enable or disable it.

     for (i=0; i< nm; i++)
     {
           // is it even a checkbox?
           // we won't worry about disabling this if it is the allrecipents button

           if (formElements[i].type == 'checkbox' && formElements[i].name != 'AllRecipients')
          {
                     // set the enabled property to true or false depending on the above
                     formElements[i].enabled = ea;
          }
        }

}
That should cover it for you... cheers,
Last Blog Entry: The wannabe juggler's quest (Oct 27th, 2007)
Reply With Quote
Reply

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

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

Similar Threads
Thread Thread Starter Forum Replies Last Post
delete by checkbox FlashO Classic ASP 3 Mar 30th, 2008 08:42
Checkbox Required WebNinja Starting Out 1 Jan 6th, 2008 00:36
A Solved Checkbox snow Webforumz Suggestions and Feedback 14 Sep 25th, 2007 20:11
Checkbox + databse rafi Classic ASP 4 Aug 4th, 2005 08:02
Unselecting a Checkbox malambing57 Classic ASP 2 Mar 10th, 2005 08:01


All times are GMT. The time now is 19:36.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43