Results 1 to 3 of 3

Thread: Please help: javascript to validate checkbox and textbox before submitting form

  1. #1
    Join Date
    Oct 2007
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Please help: javascript to validate checkbox and textbox before submitting form

    Hi, I am new to this forum and hoping someone here can help me...thank you in advance.

    I am making an enrollment form for a summer camp. At the end of the form, I would like the user to be required to: 1) enter his/her name in a text field, and 2) check a checkbox indicating they have accepted the terms and conditoins of camp enrollment, otherwise they should not be able to submit the form. For example:

    (CHECKBOX HERE) "By checking this box and submitting this form, I, (USER-ENTERED NAME AS A REQUIRED FIELD), agree with terms..."

    I know there is an "Accept terms and conditions script on Dynamic drive, but it does not include a required text field for the person to enter their name, only the checkbox.

    Does anyone have a javascript that can do this for me? I have been stewing and throwing my hands up in the air, completely lost so I'm hoping for help.

    Thank you again!

  2. #2
    Join Date
    Mar 2007
    Location
    Tarboro, NC
    Posts
    290
    Thanks
    8
    Thanked 2 Times in 2 Posts

    Default

    I can make something similar, but not exactly the same.

    Header code:
    Code:
      <script language="JavaScript">
    function setVisibility(id, visibility) {
    document.all[id].style.display = visibility;
    }
      </script>
    Name area & buttons:
    Code:
      <textarea>Your terms...</textarea><br>
      <br>
    Your Name: <input name="name" size="25" maxlength="255" type="text"><br>
      <br>
    I agree to the terms. <input onclick="setVisibility('submitbutton', 'inline')" 
    name="termsagree" value="agree" type="radio"><br>
      <br>
    I do not agree to the terms. <input checked="checked" onclick="setVisibility('submitbutton', 'none')" 
    name="termsagree" value="donotagree" type="radio" c><br>
      <br>
      <input id="submitbutton" style="display: none;" type="submit">
    Add that to your existing form, no need to put your terms in that box, it can be deleted. Thats as good as I can work up, and it does same thing, simpler but the name box is not required, its just first, so most people would automatically do it first. I know your going to re-order it, I don't think that script will help to much. But its worth a shot.

  3. #3
    Join Date
    Oct 2007
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thanks Tim, this should work just fine!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •