[thelist] JS Form validation - Radio buttons

Warden, Matt mwarden at odyssey-design.com
Thu Jun 21 22:32:16 CDT 2001


> 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





More information about the thelist mailing list