PDA

View Full Version : help with validating radio buttons


gcapp
04-27-2004, 05:01 PM
Can someone help me??

I have an asp form with 4 radio buttons and i want to have one button chosen before the form is submitted. I have this code snippet but if I do not check a button, the form still submits:
<head>
<SCRIPT language="JavaScript">

function Validate() {

if ((document.contest.Website.check == true) || (document.contest.Radio.checked == true) || (document.contest.Print.checked == true || (document.contest.Other.checked == true) {
return true;
}
else {
return false;
}

}

</script>
</head>

<form method="post" action="contest.asp" name="contest" onSubmit="return Validate()">

<input type="radio" value="1" name="Website>Website
<input type="radio" value="1" name="Radio">Radio
<input type="radio" value="1" name="Print">Print Ad
<input type="radio" value="1" name="Other">Other

How do I get the form to give a message stating that a button needs to be checked and to not submit if a button is not checked??

Any help would be appreciated.

raf
04-27-2004, 08:08 PM
Checking before submitting means javascript. Means your in the wrong forum ...

glenngv
04-28-2004, 05:19 AM
But you also need to validate on the server-side as javascript validation can be bypassed or disabled.

Do you really want to use radio buttons on your items? You have different names for the radios. That means you can select all items. If that's really what you want, you should use checboxes instead. If not, you have to name them the same.

Roy Sinclair
04-28-2004, 04:26 PM
Your javascript validation itself is failing because you've misspelled "checked" on the very first item as well.

gcapp
04-28-2004, 05:40 PM
Thanks for your help - I have posted another message pertaining to asp - hopefully someone can help me with that issue as well.