$(document).ready(function() { var $submit = $("input[type=submit]"), $inputs = $('input[type=text], input[type=password]'); function checkEmpty() { // filter over the empty inputs return $inputs.filter(function() { return !$.trim(this.value); }).length === 0; } $inputs.on('blur', function() { $submit.prop("disabled", !checkEmpty()); }).blur(); // trigger an initial blur });
Working example
Instead of blurring, you can also use keyup like:
$inputs.on('keyup', function() { $submit.prop("disabled", !checkEmpty()); }).keyup();
You can also combine several events:
$inputs.on('keyup blur', function() { $submit.prop("disabled", !checkEmpty()); }).keyup();
source share