Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Auto Tab to the next input field when 1 character is filled with an input field disabled

Hello friends I want to do Auto tab to next input field when fill 4 characters but 1 character and if there is a disabled input field that passes to the next enabled

How are you these questions? Auto tab to next input field when fill 4 characters

<input class="inputs" type="text" maxlength="1" />
<input class="inputs" type="text" maxlength="1" />
<input class="inputs" type="text" maxlength="1" disabled="disabled" />
<input class="inputs" type="text" maxlength="1" />
<input class="inputs" type="text" maxlength="1" disabled="disabled"  />
<input class="inputs" type="text" maxlength="1" />



$(".inputs").keyup(function () {
   if (this.value.length == this.maxLength) {
     $(this).next('.inputs').focus();
   }
});
like image 225
ammf18 Avatar asked Feb 03 '17 18:02

ammf18


People also ask

How do you activate the next input field on Enter?

Pressing enter key should set focus to next text or numeric input field (product code or quantity), skipping buttons.

How do you restrict input fields?

To give a limit to the input field, use the min and max attributes, which is to specify a maximum and minimum value for an input field respectively. To limit the number of characters, use the maxlength attribute.


1 Answers

Use nextAll() method(next() method can't use since it only selects immediate adjucent sibling) with :enabled(to get only enabled inputs) and :first(to get first or nearest one among them) pseudo-class selectors.

$(".inputs").keyup(function () {
   if (this.value.length == this.maxLength) {
     $(this).nextAll('.inputs:enabled:first').focus();
   }
});

$(".inputs").keyup(function() {
  if (this.value.length == this.maxLength) {
    $(this).nextAll('.inputs:enabled:first').focus();
  }
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input class="inputs" type="text" maxlength="1" />
<input class="inputs" type="text" maxlength="1" />
<input class="inputs" type="text" maxlength="1" disabled="disabled" />
<input class="inputs" type="text" maxlength="1" />
<input class="inputs" type="text" maxlength="1" disabled="disabled" />
<input class="inputs" type="text" maxlength="1" />
like image 166
Pranav C Balan Avatar answered Oct 19 '22 05:10

Pranav C Balan