SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Enthusiast
    Join Date
    Jan 2005
    Location
    panama
    Posts
    80
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Validating checkboxes

    Look I have 4 textboxes each one with a checkbox to disable the textbox when it's not gonna be needed, my problem is when validating, because when validating with if's I would have 13 if's with the combinations of the checkboxes I have, like.

    1, 2, 3, 4, 12, 23, 34, 14, 123, 234, 124, 134 or 1234.

    and the textboxes enabled their values will be sent to mysql to update data.

    Are the ifs my only way or is there better way.

  2. #2
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Portsmouth UK
    Posts
    1,498
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
        "http://www.w3.org/TR/html4/strict.dtd"
    >

    <
    html>

    <
    head>
      <
    title></title>
    <
    script language="JavaScript" type="text/javascript">
    <!--

    var 
    val,bxobj,ips;
    var 
    BoxAry=new Array();

    function 
    CkBx(obj,bx){
     
    bxobj=document.getElementById(bx);
     if (!
    obj.checked){
      
    bxobj.value='Disabled';
      
    bxobj.setAttribute('disabled',true);
     }
     else {
      
    bxobj.value='Enter a Value';
      
    bxobj.removeAttribute('disabled');

     }
    }

    function 
    FindBoxes(){
     
    BoxAry=new Array();
     
    ips=document.getElementsByTagName('INPUT');
     for (
    i=0;i<ips.length;i++){
      if (
    ips[i].id.substring(0,3)=='Box'){
       
    BoxAry[BoxAry.length]=ips[i]
      }
     }
    }

    function 
    Check(){
     
    val='';
     for (
    i=0;i<BoxAry.length;i++){
      if (!
    BoxAry[i].getAttribute('disabled')){
       
    val+=BoxAry[i].value+',';
      }
     }
     
    alert(val);
    }


    //-->
    </script>
    </head>

    <body onload="FindBoxes()" >


    <input id="Box1" size="10" value="Box1"><input type="checkbox" name="" checked="checked" onclick="CkBx(this,'Box1');"><br>
    <input id="Box2" size="10" value="Box2"><input type="checkbox" name="" checked="checked" onclick="CkBx(this,'Box2');"><br>
    <input id="Box3" size="10" value="Box3"><input type="checkbox" name="" checked="checked" onclick="CkBx(this,'Box3');"><br>
    <input id="Box4" size="10" value="Box4"><input type="checkbox" name="" checked="checked" onclick="CkBx(this,'Box4');"><br>
    <input type="button" name="" value="Check Boxes" onclick="javascript:Check();">

    </body>

    </html> 

  3. #3
    SitePoint Enthusiast
    Join Date
    Jan 2005
    Location
    panama
    Posts
    80
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Those javascript functions are case sensitive???

  4. #4
    SitePoint Enthusiast
    Join Date
    Jan 2005
    Location
    panama
    Posts
    80
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Oh another thing, the standard for javascript is to use semi-colon or just leave it with out it?

  5. #5
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Portsmouth UK
    Posts
    1,498
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thank you is good

  6. #6
    SitePoint Enthusiast
    Join Date
    Jan 2005
    Location
    panama
    Posts
    80
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hehe I'm sorry, really thank you for the help

  7. #7
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Portsmouth UK
    Posts
    1,498
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    JavaScript is case sensitive

    ; is recommended but not essential in most instances


Bookmarks

Posting Permissions

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