Jiggles
Jiggles

Reputation: 73

Barcode reader tab then enter

I am trying to work out a way of making A return function as a tab or vice versa. When the user scans the barcode it moves to the next text field then on the last field it submits the form. Really of sure of this and jquery/ JavaScript to make it happen!

Upvotes: 0

Views: 4501

Answers (1)

rationalboss
rationalboss

Reputation: 5389

The default behavior of barcode scanners is to input the characters followed by "enter." If you meant you want the scanner to move to the next field instead, you can block the enter with something like:

<form method="post">
<input type="text" name="barcode" id="b1" />
<input type="text" name="otherfield" id="b2" />
<input type="submit" id="submit" />
</form>
<script type="text/javascript">
$('#b1').keydown(function(e){
    if (e.keyCode == 13) { // barcode scanned!
        $('#b2').focus();
        return false; // block form from being submitted yet
    }
});
</script>

Upvotes: 3

Related Questions