Automatically focus on the next field

I have a series of fields and they are populated with a barcode scanner that simply “pastes” the scanned numbers into the field. Is there an event I could use that would detect the newly pasted text and move onto the next field?

onchange only triggers after the field loses focus and there are no keys being pressed so the onkeyup, onkeypress and onkeydown events won’t work with this either.


Can you script it so that the field will .blur() after the paste?


How will I know when to blur if I can’t find an event to detect when something has been pasted?

How about this:

  1. Make sure the first field does not have focus at the start, by letting the focus rest an another element.
  2. If something gets pasted into the first field, it gets focus. Make an onfocus script that then checks for e.g. length or type of characters of the pasted content.
  3. If the pasted content matches certain criteria, have the script lay the focus on the second field.

Turns out the barcode scanners input each number in the code one at a time, triggering onkeyup, onkeydown, and onkeypress each time.

What I ended up doing is calling a function when onkeypress is fired that creates a timeout that calls another function to move the focus to the next field after 200ms.

Seems to work perfectly.