radio buttons are an array in javascript.  you'll need to loop over
the radio button array and check to see if one is checked or not.

function checkform(form) {
     var checked = 0;
     for (var i=0; i<form.sitetype.length; i++) {
          if (form.sitetype[i].checked == true) {
               checked++;
               break;
          }
     }
     if (checked == 0) {
          alert("you did not check a radio button");
          return false;
     }
     return true;
}


On 4/28/06, Orlini, Robert <[EMAIL PROTECTED]> wrote:
> Hello,
>
> I have a field named "sitetype" which is a group name setup as a radio button.
>
> The script below does not seem to recognize it since it does not generate the 
> alert when the radio button is not selected. All the cases are correct for 
> the name. Is there something missing in the JavaScript below or is a radio 
> button group field name different?
>
> The "onsubmit="return checkform(this);" section is in the <form> parameter.
>
> Thanks.
>
> RO
> HWW
>
> <script language="JavaScript" type="text/javascript">
> <!--
> function checkform ( form )
> {
>   // ** START **
>   if (form.sitetype.value == "") {
>     alert( "Please enter a site type." );
>     form.sitetype.focus();
>     return false ;
>   }
>   // ** END **
>
>   return true ;
> }
> //-->
> </script>
>
>
>
>
>
> 

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Message: http://www.houseoffusion.com/lists.cfm/link=i:4:239063
Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4
Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
Donations & Support: http://www.houseoffusion.com/tiny.cfm/54

Reply via email to