jQuery – Validate the form when the submit button is clicked

Here is a simple jQuery script which could use the validate a mandatory input.

(function ($) {
  $(document).ready(function() {    
    $('#<submit-button-id>').click(function(event){    
      var x = $('<input-id>').val();
      if (x == null || x == '';) {
        alert('Please fill in the input.');
        event.preventDefault();
      }
    })
  });
})(jQuery);

 

Done =)

Reference: StackOverflow – Intercept a click on submit button and check validity of form jQuery

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s