I am facing a problem that on my webpage there is textfield that receives barcode input, The barcode is written into the field by a barcode reader device.
Now what happens is, the barcode reader after writing the barcode in the field somehow automatically submits the form. I want to prevent that submission.
I tried doing this by using preventDefault()
but still no success. Here is the code:
<form role="form" method="post" action="IssueBook" id="issueBookForm">
<input type="text" value="" required name="empId" id="empId"
onblur="getEmpData(this)" />
<input type="text" value="" required name="barcode" id="barcode"
onblur="checkBookExistence(this); checkEligibilityForUser();" />
</form>
var issueBookForm = document.getElementById("issueBookForm");
issueBookForm.addEventListener('submit', function(event) {
event.preventDefault();
});
document.getElementById("submitButton").addEventListener('click',function(event){
var choice = confirm('Are you sure you want to issue this book ?? ');
if(choice === true){
issueBookForm.submit();
}
else false;
});
Note: I only need to support browsers that have addEventListener
. I know the above won't work on old IE or IE in compatibility mode, that's fine. I'm testing in Chrome.