Since all radiobuttons must have the same name attributed to it, the trick is define the specific number of the radiobutton you want clicked IF you want the checkbox checked.
That's done by naming the array. like this:
[color red]if(document.formName.click[2].checked && !document.formName.check.checked)[/color] the 2 indicates that IF radiobutton three is clicked but the checkbox is not checked then you get an error message indicating this.
This is my version of the code, although there are other ways of doing this also:
<HTML>
<HEAD>
<SCRIPT LANGUAGE = "JavaScript">
function formCheck()
{
if(document.formName.click[2].checked && !document.formName.check.checked) {
alert("Please check the checkbox if you clicked the last radiobutton.");
return false;
}
return true;
}
</SCRIPT>
</HTML>
<BODY>
<form name="formName" method="post">
<p>
<font face="Arial, Tahoma, Verdana" size="2" color="#003399">
<input type="radio" name="click" value="yes">
click me
<input type="radio" name="click" value="yes">
click me, go ahead you know you want to
<input type="radio" name="click" value="yes">
click me and check the checkbox</font></p>
<p>
<input type="checkbox" name="check" value="has_indemnity_and_att._affirm">
<font color="003399">check me if you checked 'click me and check the checkbox'</font></p>
<p>
<input type="submit" value="Submit" onClick="return formCheck()" name="submit">
<input type="reset" value="Reset" name="reset">
</p>
</form>
<p>&nbsp; </p>
<p>&nbsp; </p>
</BODY>
</HTML>
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.