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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Clicking a certian radiobutton means you MUST check the checkbox...

Validation

Clicking a certian radiobutton means you MUST check the checkbox...

by  GUJUm0deL  Posted    (Edited  )
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 &amp;&amp; !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>&amp;nbsp; </p>
<p>&amp;nbsp; </p>
</BODY>
</HTML>


GUJUm0deL
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top