How to stop form submission when starting a barcode scanner

I am trying to stop form submission when using a barcode scanner to enter text in a selected field. When I click on the button on the scanner, it automatically tries to submit using the submit button of a higher priority on the form. I tried to use the ignore function in javascript, but cannot find the key code value for the scanner. Is there a way to set priority for different submit buttons without having to reorder them? This is how I have the buttons installed 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>
+5
source share
4 answers

, . , , , .

+3

, .

javascript false onSubmit, , . - -

<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>
+4

The best solution I've found so far

$(":input").keypress(function(event){
    if (event.which == '10' || event.which == '13') {
        event.preventDefault();
    }
});
+4
source

If the scanner provides a text box, run the form using the submit button. Show it only in the text box. This is done using javascript, not ColdFusion.

+1
source

All Articles