Tabulation via Jquery

Asked

Viewed 292 times

2

I have a field with the class "codigoBarra" where will be used barcode reader to fill it, at the end of reading with the reader it generates an n, I already managed to capture this and treat, however, when this happens, I need Focus to pass to the next field of the screen that is enabled.

exemplo

In the photo, when finishing typing the SPI, which is the number that will be read by the reader, should pass to the CNPJ because the DATE and SITUATION fields are disabled for editing.

  • How is the structure of HTML?

  • How do you check the \n in the field? You can use this same check and put the focus on the field you want. $("#campo").focus()

1 answer

1


You can try to select the next field and set the focus.

Generic example:

$(document).on('keyup', 'input[type=text]:enabled:not([readonly])', function(event){

    if ( this.value.length == $(this).attr('maxlength') ){
        // Seleciona todos os inputs que estão habilitados
        $els = $('input[type=text]:enabled:not([readonly])');
        console.log($els);
        $i   = $els.index(this);
        
        if ($els.length > ($i + 1)){
            $($els[$i+1]).focus();
        }
    }

});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<input type="text" maxlength="11" /> <br />
<input type="text" maxlength="11" disabled /> <br />
<input type="text" disabled /> <br />
<input type="text" maxlength="11" /> <br />
    <input type="text" disabled /> <br />
<input type="text" maxlength="11" /> <br />

The above example is as generic as possible, due to no code being posted in the question.

  • the next screen input is a button... I got it like this: $("input[type=text]:enabled:not([readonly]):eq(" + ( parseint( $(this).index("input[type=text]:enabled:not([readonly])")) + 1 )+ ")"). phocus();

  • So @Jonathanbarcela, as you did not post the code of your form became difficult to simulate your environment. Good that you managed.

  • Is that I can not publish the code because the copyright belongs to the company, try to explain me as much as possible in the question. Thanks for your help, @Kaduamaral.

  • Ah, tranquil @Jonathanbarcela, I know what it’s like. If my answer helped you get this result mark it as accepted. ;)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.