0

how could i get autofocus on next field after 2 digits?

Here is jquery which is not working for me -

    $("#personalDetailMobilePhoneAreaInput").keyup(function () {
        if (this.value.length == this.maxLength) {
            $(this).next(':input').focus();
        }
    });

          @Html.TextBoxFor(m => m.CommunicationView.MobilePhone.Area, new { @id = "personalDetailMobilePhoneAreaInput",  @class="customText wdt80 numericValue",type = "text",maxlength="2" })
          @Html.ValidationMessageFor(m => m.CommunicationView.MobilePhone.Area)

          @Html.TextBoxFor(m => m.CommunicationView.MobilePhone.Number, new { @id = "personalDetailMobilePhoneNumberInput",  @class="customText wdt120 mrglft10 phnIE numericValue",type = "text",maxlength="8" })
          @Html.ValidationMessageFor(m => m.CommunicationView.MobilePhone.Number)
user845405
  • 1,461
  • 5
  • 23
  • 43
  • http://stackoverflow.com/questions/15595652/focus-next-input-once-reaching-maxlength-value – JB06 Oct 30 '14 at 15:38

1 Answers1

0

Try this:

$('#personalDetailMobilePhoneAreaInput').keyup(function(){

    var maxLength = $(this).attr('maxlength');
    var currLength = $(this).val().length;        

    if(currLength >= maxLength) 
        $(this).siblings('input').focus();
});

Try it yourself: http://jsfiddle.net/4kjh44Lm/

Thiago Lunardi
  • 749
  • 1
  • 5
  • 19