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 2 of 2
  1. #1
    Regular Coder
    Join Date
    Jul 2006
    Posts
    138
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Radio button validation

    I got this code from javascriptkit. And I added a few code to validate the radio button and checked boxes. It works for check boxes but not for radio buttons

    Code:
    function checkrequired(which){
    
    var btn = valButton(document.Reg.race);
    
    var pass=true
    if (document.images){
    for (i=0;i<which.length;i++){
    var tempobj=which.elements[i]
    
    if (tempobj.name.substring(0,8)=="required"){
    
    //All the document.Reg.box<number>.checked  == false are to check for check boxes
    
    if (((tempobj.type=="text"||tempobj.type=="textarea")&&tempobj.value=='')||(tempobj.type.toString().charAt(0)=="s"&&tempobj.selectedIndex==-1) || (document.Reg.box1.checked == false && document.Reg.box2.checked == false && document.Reg.box3.checked == false && btn == null )){
    pass=false
    break
    }
    }
    }
    }
    if (!pass){
    alert("One or more of the required elements are not completed. Please complete them, then submit again! Please Make sure you select at least one checkbox")
    return false
    }
    else
    return true
    }
    
    //To validate radio buttons
    
    function valButton(btn) {
        var cnt = -1;
        for (var i=btn.length-1; i > -1; i--) {
            if (btn[i].checked) {cnt = i; i = -1;}
        }
        if (cnt > -1) return btn[cnt].value;
        else return null;
    }
    Help please !

    Thanks

    Anyone?
    Last edited by neo_philiac; 08-28-2008 at 01:36 PM.

  • #2
    Regular Coder
    Join Date
    Jul 2006
    Posts
    138
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Anyone? I have multiple members in the same group!

    Code:
        <td width="314" height="24"> <span class="body">
        <Input type = 'Radio' Name ='race' value= 'Male'>Male
    	<Input type = 'Radio' Name ='race' value= 'Female'>Female<br>
        </span>


  •  

    Posting Permissions

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