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()
}