I am trying to stop a form from submitting when using a barcode scanner to input text into the highlighted field. When I press the button on the scanner it automatically tries to submit using a higher precedence submit button in the form. I have tried to use an ignore function in javascript but can't find the key code value for the scanner. Is there a way to set the precedence of the different submit buttons without having to rearrange them? This is how I have the buttons set up in the code:
<li>
<cfinput type="submit" name="add" value="Enter Package">
<cfinput type="submit" name="search" value="Search">
<cfinput type="submit" name="reset" value="Reset">
</li>
</ul>
</td>
<td>
<center><div id="labelImageDiv">
<img id="labelImage" src="" alt="label preview"/>
</div>
<ul>
<li>
<label for="printersSelect" class="left">Printer:</label>
<select id="printersSelect" class="right"></select>
<button id="printButton">Print</button>
</li>
<li>
<div class="packHead">Package Pickup</div>
<label for="pickup" class="left">Scan Barcode:</label>
<div class="right">
<cfinput type="text" name="pickup">
</div>
</li>
<li>
<div id="pickButton">
<cfinput type="submit" name="pkgPickup" value="PickUp">
</div>
</li>
</ul>
Best solution I have found so far
$(":input").keypress(function(event){
if (event.which == '10' || event.which == '13') {
event.preventDefault();
}
});
I voted for existdissolve's answer because the scanner should be configurable.
However, a very simple javascript solution would be to return false onSubmit unless the submit button is actually clicked allowing the form to be submitted. Something like this --
<script language="javascript">var p = false;</script>
<form method="post" onsubmit = "return(p)">
<input type = "text" name = "text" />
<input type = "submit" value = "submit" name = "submit" onClick = "javascript: p=true;" />
</form>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With