Wrox Home  
Search P2P Archive for: Go

  Return to Index  

javascript thread: Radio Button Validation


Message #1 by "Nathan Nelson" <nmnelson@k...> on Mon, 18 Jun 2001 14:40:02 -0600
Yo might try the following function...

function RadioValidate( CurField ) {
// CurField is the object you wish to check (document.myform.myradio).
 var Selected = false;
 for ( var i=0; i < CurField.length; i++ ){
      if ( CurField[i].checked ) {
       Selected = true;
    break;
   }
 }
 if (Selected == false){
    alert( CurField.name + " must be selected.");
}
 return Selected;
}

"Alex Shiell, ITS, EC, SE" wrote:

> You have to check the "checked" property of each radio button individually
>
> e.g.
>
> if(!(document.forms[0].btnRadio[0].checked ||
> document.forms[0].btnRadio[1].checked){
>         alert("Please click a radio button!");
> }
>
> -----Original Message-----
> From: Nathan Nelson [mailto:nmnelson@k...]
> Sent: 18 June 2001 21:40
> To: javascript
> Subject: [javascript] Radio Button Validation
>
> How would I test to see if a user has selected a radio button so I can make
> it required that the user either chooses "YES" or "NO" using Javascript?
>
> Thank you in advance
>
> Nathan Nelson
>


  Return to Index