[thelist] JS Form validation - Radio buttons - solution

CDitty mail at redhotsweeps.com
Thu Jun 21 22:54:36 CDT 2001


Got it.  I tried if(!(form.userid[0].checked)){ and it is working.

Thanks for helping.

Chris

At 10:28 PM 6/21/2001, you wrote:
> > From: "CDitty" <mail at redhotsweeps.com>
> > Subject: [thelist] JS Form validation - Radio buttons
> >
>
> > Can anyone tell me what is wrong with this function?  I cannot get it to
> > work correctly.
> >
> > function query_validator(form){
> >          if(form.userid.unchecked == false){
> >                  alert('You must choose a user to process.');
> >          return(false);
> >          }
> > }
>
>You sure you're not getting an error? I don't believe "unchecked" is a valid
>property. The property is "checked".
>
>function query_validator(form){
>          if(document.form.userid.checked == false){
>                  alert('You must choose a user to process.');
>          return(false);
>          }
>}
>
>Also, if you have more than one radio, you will have to loop through them
>all and check each one as such (untested):
>
>function query_validator(form){
>     var isOneChecked = false;
>     for (var i=0; i < document.form.userid.length; i++)
>     {
>          if(document.form.userid[i].checked){
>             isOneChecked = true;
>             break;
>          }
>     }
>
>     if (!isOneChecked) {
>         alert('You must choose a user to process.');
>          return(false);
>     }
>}
>
>
>
>hth,
>
>
>--
>mattwarden
>mattwarden.com
>
>
>---------------------------------------
>For unsubscribe and other options, including
>the Tip Harvester and archive of TheList go to:
>http://lists.evolt.org Workers of the Web, evolt !





More information about the thelist mailing list