Skip to content

Instantly share code, notes, and snippets.

@mohshbool
Created April 18, 2019 16:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mohshbool/8afc7ab0427ffb0c12ba35da57f1ebb8 to your computer and use it in GitHub Desktop.
Save mohshbool/8afc7ab0427ffb0c12ba35da57f1ebb8 to your computer and use it in GitHub Desktop.
Validate form function using jQuery@^3.x
const validateForm = () => {
$('input').each(function() {
const $this = $(this);
const $button = $('button');
if ($this.val() === '' || $this.val().length <= 0) {
$button.attr('disabled', 'disabled');
} else if (!$button.attr('disabled')) {
$button.removeAttr('disabled');
}
})
}
$('input').on('input', validateForm);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment