user1894647
user1894647

Reputation: 663

Avoid auto submit form after scanning thru barcode scanner

HTML

<form action="die_issue_process.php" id="form" method="post" autocomplete="off">
<input type="text" name="item_name[]"  />
<input type="button" name="add_item" value="Add More" onClick="addMore();" />
<input type="submit" id="Search" name="Search" value="Search" />

Javascript code:

function addMore() {
$("<DIV>").load("input.php", function() {
$("#product").append($(this).html());
}); 
}

Friends in this form I have single text box and add button to add text box according to the need. Here in this form I'm giving input thru a BAR CODE reader so once the bar-code is scanned the form gets automatically submitted but my requirement is it should be submitted only after giving the submit button

Note: my form gets auto submitted on first scan of input box itself.

Upvotes: 1

Views: 6493

Answers (3)

Lee Kowalkowski
Lee Kowalkowski

Reputation: 11751

You can consider a barcode scanner as a very specialised keyboard. If you test your barcode scanner whilst in a text editor. You will see they just very quickly enter the string that the barcode represents, followed by a carriage return.

These are indistinguishable from the keystrokes required to manually perform the same operation, using the keyboard.

If you are focused on a text field in a form, pressing enter will often submit the form.

To prevent the enter key from submitting a form on a text field, you can kill that keystroke with an event handler, for example:

(function() {
    var textField = document.getElementById('textFieldId');

    if(textField) {
        textField.addEventListener('keydown', function(mozEvent) {
            var event = window.event || mozEvent;
            if(event.keyCode === 13) {
                event.preventDefault();
            }
        });
    }
})();

Upvotes: 2

theshemul
theshemul

Reputation: 418

If the scanner is feeding to a textbox, start your form with your submit button hidden. Only visiable it once the textbox has data input. this can be done by javascript..

Upvotes: 0

deviloper
deviloper

Reputation: 7240

Well, a barcode scanner, reads the barcode and submits automatically! So I think you better change your input with the type "submit" to a button

<input type="button" id="Search" name="Search" value="Search" />

Upvotes: 1

Related Questions