Tab via Jquery

2

I have a field with the "Barcode" class where a barcode reader will be used to fill it, at the end of the reading with the reader it will generate a \ n, I could already capture it and treat it, however, when that happens , I need to focus to the next field on the screen that is enabled.

In the photo, when you finish entering the SPI, which is the number that will be read by the reader, you must go to the CNPJ because the DATA and SITUATION fields are disabled for editing.

    
asked by anonymous 17.07.2015 / 19:41

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><inputtype="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 because no code has been posted in the question.

    
17.07.2015 / 20:54