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
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> 

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

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}

 

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.