Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    May 2004
    Posts
    391
    Thanks
    76
    Thanked 0 Times in 0 Posts

    checkbox disabled

    Hi all
    The below script will mark all checkbox on or off. How can I get it to skip the checkboxes that are DISABLED?
    Tracy

    function checkAll(theForm, cName, status,el,color) {
    for (i=0,n=theForm.elements.length;i<n;i++)
    if (theForm.elements[i].className.indexOf(cName) !=-1) {
    theForm.elements[i].checked = status;
    }

    }

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,919
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    if (formName.elements[i].disabled==true)
    {
    formName.elements[i].checked=false;
    }

  • #3
    Senior Coder
    Join Date
    Mar 2005
    Location
    Portsmouth UK
    Posts
    4,505
    Thanks
    3
    Thanked 501 Times in 488 Posts
    easiest way of doing this is to assign a property to the emement when disabled
    as example (just posted on another of your posts)

    f40_obj.ary[f40_1].ckdisabled=true;

    set this to false when disabl is removed

    then in verification


    function checkAll(theForm, cName, status,el,color) {
    for (i=0,n=theForm.elements.length;i<n;i++)
    if (theForm.elements[i].className.indexOf(cName) !=-1&&!theForm.elements[i].ckdisabled) {
    theForm.elements[i].checked = status;
    }

    }

    example snippet
    Code:
    ..............................
     }
     for (f40_1=0;f40_1<f40_obj.ary.length;f40_1++){
      f40_obj.ary[f40_1].ckdisabled=false;
      f40_obj.ary[f40_1].removeAttribute('disabled');
     }
     if (f40_obj.checked==f40_state){
      for (f40_2=0;f40_2<f40_obj.ary.length;f40_2++){
        f40_obj.ary[f40_1].ckdisabled=true;
        f40_obj.ary[f40_2].setAttribute('disabled','disabled');
      }
     }
     f40_obj.removeAttribute('disabled');
    }
    
    function f40_AllElements(f40_){
      if (f40_.all){ return f40_.all; }
      return f40_.getElementsByTagName('*');
    }
    ...............

  • #4
    Senior Coder
    Join Date
    Mar 2005
    Location
    Portsmouth UK
    Posts
    4,505
    Thanks
    3
    Thanked 501 Times in 488 Posts
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
        "http://www.w3.org/TR/html4/loose.dtd">
    
    <html>
    
    <head>
      <title></title>
    <script language="JavaScript" type="text/javascript">
    <!--
    // by Vic Phillips (23-10-2005) http://www.vicsjavascripts.org.uk
    // checks if form elements are disabled
    // and the element property 'ckdisabled=true' if disabled
    // This property can be used in form verification to inhibit verification if true
    // e.g.
    // function checkAll(theForm, cName, status,el,color) {
    //  for (i=0,n=theForm.elements.length;i<n;i++)
    //   if (theForm.elements[i].className.indexOf(cName) !=-1&&!theForm.elements[i].ckdisabled) {
    //    theForm.elements[i].checked = status;
    //   }
    //  }
    // }
    
    // The property  'ckdisabled' must be set to  property 'ckdisabled=false'
    // if the element is enabled
    
    // The utility will set all 'radio' buttons of the same name to disable="disable"
    // if one 'radio' of that name is disabled.
    
    
    // The utility is initialised by a <BODY> onload event
    // <body onload="zxcCkDisabled('*FormID*');">
    // where *FormID* = the unique ID of the form or element containing the inputs (string)
    
    // Functional Code - No Need to Change
    
    function zxcCkDisabled(zxcid){
     zxcobj=document.getElementById(zxcid);
     zxcels=zxcAllElements(zxcobj);
     for (zxc0=0;zxc0<zxcels.length;zxc0++){
      if (zxcels[zxc0].tagName=='INPUT'||zxcels[zxc0].tagName=='TEXTAREA'||zxcels[zxc0].tagName=='SELECT'){
       if (zxcels[zxc0].getAttribute('disabled')){
        if (zxcels[zxc0].disabled||zxcels[zxc0].disabled=='disabled'){
         zxcels[zxc0].ckdisabled=true;
         if (zxcels[zxc0].type=='radio'){
          for (zxc1=0;zxc1<zxcels.length;zxc1++){
           if (zxcels[zxc0].name==zxcels[zxc1].name){
            zxcels[zxc1].ckdisabled=true;
            zxcels[zxc1].setAttribute('disabled','disabled');
           }
          }
         }
        }
       }
      }
     }
    }
    
    function zxcAllElements(zxc){
     if (zxc.all){ return zxc.all; }
     return zxc.getElementsByTagName('*');
    }
    
    //-->
    </script>
    
    </head>
    
    <body onload="zxcCkDisabled('Form1');">
    <form id="Form1" >
    <input disabled="disabled" >
    <select disabled="disabled" ><option>Select Box</option></select>
    <input type="radio" name ="fred" disabled="disabled" >
    <input type="radio" name ="fred"  >
    <input type="checkbox" >
    
    </form>
    </body>
    
    </html>


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •