Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    sdg
    sdg is offline
    New to the CF scene
    Join Date
    Jul 2002
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Form Validation-Submitting When Fields Not Complete

    Hello,

    I have some Javascript that checks to see if the user has entered all the required fields. If the fields are left blank, then a message appears telling them that they didn't complete the particular field.

    This part of the code works just fine, but after the user clicks the "OK" button to close the message, the code proceeds to submit the form regardless.

    Here is the Javascript:

    function verify() {
    var themessage = "You are required to complete the following fields: ";

    if ((document.formx.Chapter[0].checked == false) && (document.formx.Chapter[1].checked == false)) {
    themessage = themessage + " - Chapter";
    }

    if (themessage == "You are required to complete the following fields: ") {
    return(true);
    }
    else {
    alert(themessage);
    return(false);
    }
    }
    // End -->

    </script>


    Here is the portion of the HTML that calls the submit:

    <form name="formx" method="post" action="submit.asp" onSubmit="verify();">

    Here is the portion of the HTML of the form where the "Chapter" option is selected:

    <INPUT type="radio" name="Chapter" value="Philadelphia" size="20"></FONT><FONT face="Garamond">Philadelphia</FONT><FONT size="2" face="Arial"><BR>
    <INPUT type="radio" name="Chapter" value="Triple Cities"></FONT><FONT face="Garamond">Triple
    Cities</FONT></p>


    I can also provide the URL to test it out yourself.

    Much thanks in advance.

    -Scott

  • #2
    Regular Coder
    Join Date
    May 2002
    Location
    Helsinki, Finland
    Posts
    231
    Thanks
    0
    Thanked 1 Time in 1 Post
    I made a fully functional yet compact example once. It can be found from : http://www24.brinkster.com/zvona/zValidate.html .
    The fields and dialogs are in Finnish, but I think you get the idea anyway.
    Zvona
    First Aid for
    Web Design

  • #3
    Regular Coder
    Join Date
    Jun 2002
    Location
    Delaware, USA
    Posts
    138
    Thanks
    0
    Thanked 0 Times in 0 Posts
    add return to your onSubmit

    onSubmit="return verify();">


  •  

    Posting Permissions

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