I have a real basic form (code below) with a bunch of back-panel PhP. There is a scanner being used to input the data, but instead of tab after each item, it sends an “enter” command.
Is it viable to add javascript to cause enter to instead tab to the next form field, and upon the last form field, submit it instead? I have found a few scripts online, but none that I have tried have worked in Firefox/Chrome.
CODE:
<html><head><title>Barcode Generation</title></head><body>
<fieldset style="width: 300px;">
<form action="generator.php" method="post">
Invoice Number:<input type="text" name="invoice" /><br />
Model Number:<input type="text" name="model" /><br />
Serial Number:<input type="text" name="serial" /><br />
<input type="hidden" name="reload" value="true" />
<input type="submit" />
</form><br /><a href=null>en espanol</a></fieldset>
</body></html>
Yes.
You’ll need to implement an ‘onsubmit’ handler for the form which checks that the [ENTER] key was pressed from the “correct” field (or the form is adequately filled). If not, the handler should just return false (to prevent submission).(Only need to do the next bit.)Then you’ll need to implement an ‘onkeypress’ handler for each input that can be scanned, and when you get an [ENTER] key,
call .preventDefault()prevent submission of the form, andtrigger a [TAB] ‘keypress’ event.focus() the next field.Update: this works for me:
Updated: to submit on [ENTER] in ‘serial’ field.
Updated: to properly validate in all cases.