To make the submit button disable until all the fields have some values, we will be using keyup() function that provide handler to check not null values.
We disabled the register button in the starting and according to the value from handler, we are retaining or removing the disabled property from submit button.
![](https://mcusercontent.com/c5504cc750e8fae7e0e53dfd7/images/b12e9489-b472-4add-a714-139af82ec1a8.png)
Let's see the Example:
index.html
<form>
Username<br />
<input type="text" id="user" name="user" /><br />
Password<br />
<input type="password" id="pass" name="pass" /><br />
<input type="submit" id="register" value="Register" disabled="disabled" />
</form>
abc.js
(function() {
$('form > input').keyup(function() {
var empty = false;
$('form > input').each(function() {
if ($(this).val() == '')
{
empty = true;
}
});
if (empty)
{
$('#register').attr('disabled', 'disabled');
}
else
{
$('#register').removeAttr('disabled');
}
});
})()
Hope this helps you :)
For any questions or doubt please ask in comments section below.
0 Comment(s)