Jump to content

radio button validation


angel777

Recommended Posts

hi.. i have asked this to javascript site here.. but no one reply..

 

i tried to put validation for radio button.. but fail..

 

 

if(!document.change.r1.checked== true) {

      window.alert('Please check the X- Ray facilities');

      return false;

 

...

}

the change = my form name, r1 = radiobutt name 

 

it pop out ... but after i check the radio..  it still pop out

Link to comment
https://forums.phpfreaks.com/topic/98553-radio-button-validation/
Share on other sites

<html>
<head>
<meta name="generator" content="PhpED Version 4.5 (Build 4513)">
<title>sample</title>
<meta name="author" content="barand">
<meta name="creation-date" content="03/30/2008">
<script language='javascript'>
         function checkRB(form)
         {
             var k = form.elements.length;
             for (var i=0; i<k; i++)
             if (form.elements[i].name =="rb" && form.elements[i].checked==true)
             {
                return true;
             }
             alert("Not checked") ;
             return false;
         }
</script>
</head>
<body>
<form onsubmit="return checkRB(this)">
       <input type="radio" name="rb" value="1"> 1
       <input type="radio" name="rb" value="2"> 2
       <input type="radio" name="rb" value="3"> 3
       <br/>
       <input type="submit" name="sub" value="Do">
</form>
</body>
</html> 

Hi, I can't seem to get that to work for me.

 

I cannot put that in my header so I have put it just before the <form> tag and also changed name to the field name of the two fields in the group, So it looks like this:

 


<script language='javascript'>
         function checkRB(form2)
         {
             var k = form.elements.length;
             for (var i=0; i<k; i++)
             if (form.elements[i].carnessary =="rb" && form.elements[i].checked==true)
             {
                return true;
             }
             alert("Not checked") ;
             return false;
         }
</script>

thanks for the reply...

 

but my problem is not on multiple checkbox with that for loop..

 

i wonder can i put like this ?

 

if(!document.change.r1.checked== true)

{

      window.alert('Please check the X- Ray facilities');

      return false;

}

else

{return true}

 

 

This is doing my head in, answere is prob so simple. I ahve tried using:

 


<script type="text/javascript">
<!--

function validate_form ( )
{
    valid = true;

  if ( ( document.form2.cult[0].checked == false )
    && ( document.form2.cult[1].checked == false ) )
    {
        alert ( "Please choose select yes or no!" );
        valid = false;
    }

    return valid;
}

//-->
</script

 

 

yet, it still does not work!

 

Cheers

Sean

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.