Above given is the fiddle.
I have a simple login form. Username, password textfield & a submit button. Submit button is kept disabled until both username & password is entered. And I have successfully done that using the jQuery function given below.
var $input = $('input'),
$register = $('#signin');
$register.attr('disabled', true);
$input.keyup(function() {
var trigger = false;
$input.each(function() {
if (!$(this).val()) {
trigger = true;
}
});
trigger ? $register.attr('disabled', true) : $register.removeAttr('disabled');
});
Given below is my form.
<div class="form-group">
<label for="txtusername" class="col-sm-4 control-label">Username</label>
<div class="col-sm-8">
<input type="text" class="form-control" id="txtusername" name="txtusername" placeholder="Username">
</div>
</div>
<div class="form-group">
<label for="txtpassword" class="col-sm-4 control-label">Password</label>
<div class="col-sm-8">
<input type="password" class="form-control" id="txtpassword" name="txtpassword" placeholder="Password">
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-4 col-sm-8">
<div class="checkbox">
<label><input type="checkbox">Remember me</label>
</div>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-4 col-sm-8">
<button type="submit" id="signin" class="btn btn-default" >Sign in</button>
</div>
You know when a user enters his credentials and submits the button, web browsers ask for storing password & if the user clicks yes, his password & username is stored in the browser. So the next time, when he visits the page, his username & password is already filled in the filed. Now comes the problem, even though the web browser (chrome, firefox) automatically filled in the form for the user, the button is still disabled. For enabling the button, user needs to enter any one of fields (even a single alphabet) of the fields for enabling that button. Technically speaking, this is not right. As data is already filled in the form (by the browser), the button has to be enabled. Any suggestions to make it as like that???