Try to use:
$('#ssn').keyup(function() {
if(this.value.length == this.maxLength) {
$('input[type="submit"]').click();
}
})
Question
I got a login form, maxlength of empNum and ssn is 4. Here is my code HTML:
<input type="text" id="empNo" name="empNo" style="width: 90px; margin-left: 10px" maxlength="4" onkeyup="nextField(this, 'ssn')"/>
<input type="text" id="ssn" name="ssn" style="width: 90px; margin-left: 10px" maxlength="4" onkeyup="nextField(this, 'submit')"/>
<input type="submit" class="btn btn-success"
style="font-weight: bold;display: inline; margin-top: 5px;"
value="Login">
javascript:
function nextField(current, nextFieldID) {
if (current.value.length >= current.maxLength) {
document.getElementById(nextFieldID).focus();
}
}
It means that when I fill empNum with 4 characters, it's auto tab to ssn field. How can I fill 4 characters of ssn, it will auto login instead of press login button.
Solution
Try to use:
$('#ssn').keyup(function() {
if(this.value.length == this.maxLength) {
$('input[type="submit"]').click();
}
})