Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6615335
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T20:26:58+00:00 2026-05-25T20:26:58+00:00

Using HTML5 validation… In HTML5 browsers, validation occurs before the submit event. So if

  • 0

Using HTML5 validation…

In HTML5 browsers, validation occurs before the submit event. So if the form is invalid, the submit event never fires.

I would like to hook an event into the form submit, to fire whether the form validates or not. Here’s a small example, where I’m trying to alert() when the user submits the form.

HTML:

<!DOCTYPE html>
<html>
    <head><title>Example</title></head>
    <body>
        <form>
            <input type="text" name="foo" required title="Foo field"/>
            <input type="submit"/>
        </form>
    </body>
</html>

JavaScript:

$(function() {
    $('form').submit(function() {
        alert('submit!')
    });
});

Interactive demo: http://jsfiddle.net/gCBbR/

My question is: do browsers provide an alternative event that I can bind to that will run before the validation?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T20:26:58+00:00Added an answer on May 25, 2026 at 8:26 pm

    Yes, there is an event for that reason. The event is called invalid when user tries to submit the for orr when you check validity via HTML5 validation method checkValidity(). This event does not fire on blur or something like that without calling checkValidity() just because you have HTML validation attributes in your input tags. But it does fire on before form submit.

    From W3C:

    When the checkValidity() method is invoked, if the element is a
    candidate for constraint validation and does not satisfy its
    constraints, the user agent must fire a simple event named invalid
    that is cancelable (but in this case has no default action) at the
    element and return false. Otherwise, it must only return true without
    doing anything else.

    For example you have this markup:

    <form>
                <input type="text" name="foo" required title="Foo field"/>
                <input type="submit"/>
    </form>
    

    Then you need to call checkValidity() to fire invalid event if the input data is invalid:

    document.querySelectorAll('input')[0].addEventListener('blur', function(){
            this.checkValidity();
        }, false);
    
    document.querySelectorAll('input')[0].addEventListener('invalid', function(){
            console.log('invalid fired');
        }, false);
    

    Look at my example here: http://jsbin.com/eluwir/2

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing form and adding html5 validation attributes to its input like required, autofocus.
I'd like to start using HTML5's basic features, but at the same time, keep
So I'm coding a registration form, and I would like to have virtual placeholders,
Anyone who know how I can trigger the standard HTML5 validation in a form
I'm using the current version of ASP.net MVC to display a form. Validation is
I'm using (or trying to) JQuery Validation with WebForms/html. I have, basically (simplifying the
I am using curl like this: curl -s -F uploaded_file=@/path_to_file;type=text/html -F output=soap12 http://localhost/w3c-markup-validator/check >text.xml
I'm experimenting with using html5 and css counters to number the figures in a
I am looking at using HTML5 Canvas element for my upcoming project. I want
I'm using the HTML5 elements and in a project i'm working on and the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.