Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

Troubleshooting
Research
Professional Opinions
Ask a Question
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

troubleshooting Question

How can I make radio buttons mandatory fields?

Avatar of baxtalo
baxtalo asked on
JavaScriptASP
4 Comments1 Solution546 ViewsLast Modified:
Hi Experts,
I have these radio buttons on my page and my users tend to skip checking the No value. How could I make it mandatory? Please see the code below, what do I have to add?
Thank you.
<html>
<head>
<title>Radio Button</title>
<script language="JavaScript" type="text/JavaScript">
<!--
function uncheckRadio() {
 var choice = document.form1.Sleepy;
 for (i = 0; i < choice.length; i++) {
  if ( choice[i].checked = true )
   choice[i].checked = false;
 }
}

function uncheckRadio1(){
 var choice = document.form1.Thirsty;
 for (i = 0; i < choice.length; i++) {
  if ( choice[i].checked = true )
   choice[i].checked = false;
 }
}

function uncheckRadio2(){
 var choice = document.form1.Hungry;
 for (i = 0; i < choice.length; i++) {
  if ( choice[i].checked = true )
   choice[i].checked = false;
 }
}

//-->
</script>
</head>

<body>

<form method="post" action="MyPage.asp">
<table>
<tr><td align="right">
<b>Are you sleepy?&nbsp;&nbsp;</b>
</td><td>
<label>
<input type="radio" name="Sleepy" value="Yes" ondblclick="uncheckRadio();"><b>Yes</b></label>
</td><td>&nbsp;&nbsp;&nbsp;
<label><input type="radio" name="Sleepy" value="No" ondblclick="uncheckRadio();"><b>No</b></label>
</td></tr>
<tr><td colspan="3">&nbsp;</td></tr>
<tr><td align="right">
<b>Are you thirsty?&nbsp;&nbsp;</b>
</td><td>
<label>
<input type="radio" name="Thirsty" value="Yes" ondblclick="uncheckRadio();"><b>Yes</b></label>
</td><td>&nbsp;&nbsp;&nbsp;
<label><input type="radio" name="Thirsty" value="No" ondblclick="uncheckRadio();"><b>No</b></label>
</td></tr>
<tr><td colspan="3">&nbsp;</td></tr>
<tr><td align="right">
<b>Are you hungry?&nbsp;&nbsp;</b>
</td><td>
<label>
<input type="radio" name="Hungry" value="Yes" ondblclick="uncheckRadio();"><b>Yes</b></label>
</td><td>&nbsp;&nbsp;&nbsp;
<label><input type="radio" name="Hungry" value="No" ondblclick="uncheckRadio();"><b>No</b></label>
</td></tr>
</table>
<input type="submit" name="Submit" id="flashingtext" value="Submit" />

</body>
</html>
ASKER CERTIFIED SOLUTION
Avatar of leakim971
leakim971Flag of Guadeloupe imageMultitechnician
Commented:
This problem has been solved!
Unlock 1 Answer and 4 Comments.
See Answers