INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Validation

Clicking a certian radiobutton means you MUST check the checkbox... by GUJUm0deL
Posted: 20 Jan 01

  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:
if(document.formName.click[2].checked && !document.formName.check.checked) 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>


GUJUm0deL

Back to Javascript FAQ Index
Back to Javascript Forum

My Archive

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close