validation in radio button

M

Matt

The following code is try to validate if the user selects a radio button
choice. I dont understand why document.UserInputs.question.value; gets
undefined value even user make a choice. I tried text box and drop down
list, and it works fine.

<html>

<head>
<script type="text/javascript">
function CheckForm()
{
var radiochoice = document.UserInputs.question.value;
document.write("choice = " + radiochoice);
if(radiochoice != "yes" && radiochoice != "no")
{
alert("Choose the radio button");
document.UserInputs.radiogroup.focus();
return false;
}
document.UserInputs.submit();
}
</script>

</head>
<body>

<form action="formtestprocess.asp" name="UserInputs" method="post"
onsubmit="return CheckForm()">

<P>Yes<input type="radio" name="question" value="yes">
No<input type="radio" name="question" value="no">
<P><input type="submit" name="submitbutton" value="submit here">
<input type="reset" name="resetbutton" value="reset here">

</form>

</body>
</html>


Please advise. Thanks!
 
D

Dave Anderson

http://www.aspfaq.com/etiquette.asp?id=5003

Asked and answered in microsoft.public.scripting.jscript.



--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms. Please do not contact
me directly or ask me to contact you directly for assistance. If your
question is worth asking, it's worth posting.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,143
Messages
2,570,822
Members
47,368
Latest member
michaelsmithh

Latest Threads

Top