CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 1 of 1
  1. #1
    Join Date
    Aug 2016
    Posts
    2

    JavaScript and Custom Error Messages on an HTML5 form

    I am trying to add custom error messages to my HTML5-based contact form, with JavaScript, and I encountered an issue in that, though I can get the custom messages to trigger when they are supposed to, they also trigger and prevent the form's submission when all fields are filled out in accordance with my intentions for a valid submission; below you will see the javaScript and corresponding HTML markup, that relates to this issue; how can I fix this?:

    Code:
    <label>Name 
    <input required id="name" name="name" placeholder="Name" tabindex="1">
    </label>
    
    <Script>
    var nError= document.getElementById("name");
    nError.checkValidity(this)
    {
        if(nError.validity.valueMissing)
        {
            nError.setCustomValidity("You need to leave your name, here.");
        }
    };
    </Script>
    Last edited by PeejAvery; September 13th, 2016 at 09:32 PM. Reason: Added code tags

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured