Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Please show me a simple validation for two radio buttons...

Status
Not open for further replies.

Olorin1

Technical User
Feb 14, 2001
17
CA
Hi there,

I'm not quite sure what im doing wrong so here is what i need. Simply, i have two radio buttons. I just need to validate if one has been checked, which one. What is the simplest way to do this, or what am i doing wrong?


here is what i've got:

<HTML>
<head>
<script language=&quot;javascript&quot;>

function validate(){

if (!document.form.waiver.checked)
{
window.alert (&quot;You must answer the waiver question.&quot;);
document.form.waiver.focus();
return false;
}

}
</script>
</head>

<body>
<form name=&quot;form&quot; onSubmit=&quot;return validate()&quot;>
<table class=&quot;tiny&quot; border=&quot;0&quot; width=&quot;100&quot; align=&quot;center&quot;>
<tr>
<td width align=&quot;right&quot; valign><input type=&quot;RADIO&quot; name=&quot;waiver&quot; value=&quot;yes&quot; size>Yes</td>
<td width align=&quot;left&quot; valign><input type=&quot;RADIO&quot; name=&quot;waiver&quot; value=&quot;no&quot; size>No</td>
</tr>
</table>

<table class=&quot;tiny&quot; border=&quot;0&quot; cellspacing=&quot;5&quot; cellpadding=&quot;0&quot; width=&quot;90%&quot;>
<tr>
<td width=&quot;&quot; align=&quot;right&quot; valign=&quot;center&quot;>
<dd><input type=&quot;Submit&quot; name=&quot;sub&quot; value=&quot;Submit&quot; align=&quot;right&quot; width=&quot;50&quot; height=&quot;50&quot;></dd>
</td>
<td width=&quot;&quot; align=&quot;left&quot; valign=&quot;center&quot;><div>
<dd><input type=&quot;Reset&quot; name value=&quot;Reset&quot; align=&quot;center&quot; width=&quot;50&quot; height=&quot;50&quot;></dd>
</div></td>
</tr>
</table>
</body>
</html>

Please and Thanks

David Stephens >:):O>
 
try:

if ((document.form.waiver.value != &quot;no&quot;) && (document.form.waiver.value != &quot;yes&quot;))
 
Checking the value of a radio button doesn't seem to work very well, at least in IE5.5. Try subscript the radio button when using &quot;checked&quot;. For example:
Code:
if document.form.waiver[0].checked // the 1st radio button
if document.form.waiver[1].checked // the 2nd radio button
Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top