I have 4 input boxes and there is common key down function:
$(".pincode-input-text").keydown(function(e) {
if($(this).val()=="") {
$(this).attr('type','number');
} else if($(this).val()!="") {
$(this).attr('type','password');
}
// check if input is numeric
var enteredValue = e.key;
if ($.isNumeric(enteredValue)) {
$(this).val(enteredValue);
$(this).next().attr('type', 'number');
$(this).next().focus();
$(this).next().val('');
$('.fn-mtd_pin_validate').nextAll('span:first').html(" ");
} else if(!$.isNumeric(enteredValue)) {
// check if input is non numeric
$(this).val('');
if(e.keyCode == 8 || e.key == "Backspace") {
$(this).prev().focus();
var elemt = new mtdMobilePin($(window.pinvalidateElemnt).attr('id'));
elemt.validate();
return false;
}
$(this).focus();
$('.fn-mtd_pin_validate').nextAll('span:first').html("Invalid Characters");
$('.fn-mtd_pin_validate').nextAll('span:first').show();
}
// Update the value of input type password after value change on any input type.
var elemt = new mtdMobilePin($(window.pinvalidateElemnt).attr('id'));
elemt.validate();
});
<span class="fn-mtd_pin_validate">
<input type="password" min="0" step="1" maxlength="1" autocomplete="off" class="form-control pincode-input-text first mtd_pin_first" tabindex="30">
<input type="password" maxlength="1" autocomplete="off" min="0" step="1" class="form-control pincode-input-text second mtd_pin_second" tabindex="31">
<input type="password" maxlength="1" autocomplete="off" min="0" step="1" class="form-control pincode-input-text third mtd_pin_third" tabindex="32">
<input type="password" maxlength="1" autocomplete="off" min="0" step="1" class="form-control pincode-input-text fourth mtd_pin_fourth" tabindex="33">
</span>
I am unable to understand, why there is value appeared on second box as soon as value entered on first one. However I am using $(this).next().val('');