0

I have made one form to enter product codes through USB barcode reader. is there mechanism in java script or jquery to auto focus to next field after scan product code through USB barcode reader vice versa.

For ex: cursor to be focused to one by one after scan product codes through barcode reader. Super market process type.

But product code size is not same. Some Product codes contain 10 digits and some product codes contain 20 digits.

Srini
  • 823
  • 5
  • 10
  • 29

1 Answers1

0

You can use the javascript .focus method to focus an input element. Like so: document.querySelector("#inputId").focus() or $("inputId").focus() if you use jQuery.

You could use the input js event to listen for changes. Go to http://jsfiddle.net/67sgxcyz/ to see an example. You get focused on the second input once you change the first.

Here is an example where I use a variable (currentInput) to keep track of which input is the current one. When we change the Input we get focused on the next one. The example is very primitive, because when you manually select any input the currentInput variable doesn't get changed. http://jsfiddle.net/snytcfz0/ (You could write all of this in pure JS, but I am to lazy)

Or you can trigger the focus not using an event listener, but simply run it after you set the content in the function that manages the product code. Like so:

    var currentInput
    function scanBarCode (code) {
        $('input')[currentInput].value = code
        currentInput++
        $('input')[currentInput].focus()
    }
Ben Bals
  • 25
  • 1
  • 5
  • Hi Ben, Thanks for quick reply. But it does not work while scanning product codes through barcode reader. – Srini Jul 04 '15 at 11:43
  • 1
    @user1702169 We need further information on your code and the system behind it to help you – Ben Bals Jul 05 '15 at 14:15