Pedram
Pedram

Reputation: 16575

jquery - change input value when go to next

When you press tab button while you typing in an input[text] you will go to next input automatically, when you fill up all inputs and after again want to re-fill them, values will highlight with blue color, so i tried to do this without pressing tab button, it's already go to next input but it will not highlight to get new value and you have to drag (select all) the value to replace new one.

so i want to when it go to next value WHEN it already filled up it get blue highlight and editable. please see my JSFiddle and fill up all input then re-fill them then you will see you can not change value until you drag the value to change.

JSFiddle

$(".digits").keyup(function () {
    if (this.value.length == this.maxLength) {
      $(this).prev('.digits').focus();
    }
});

Upvotes: 0

Views: 321

Answers (2)

Hardeep Randhawa
Hardeep Randhawa

Reputation: 47

try this Code Its Working Fine

  $(".digits").keyup(function () {

    if (this.value.length == this.maxLength) {

    $(this).prev('.digits').focus();
    $(this).prev('.digits').trigger( "select" );

}  });

Upvotes: 0

Bhushan Kawadkar
Bhushan Kawadkar

Reputation: 28513

Try this: you can add focus event handler and select all text in the input box. See below code and JSFiddle demo

$(".digits").focus(function(){
  $(this).select();
});

JSFiddle Demo

Upvotes: 1

Related Questions