input - Detect text filled by barcode scanner(reader) javascript -
the code checks barcodes using barcode scanner. search_code
filled user (keyboard) , , insert_code
filled automatically barcode scanner. currently, code works if both inputs introduced in barcode scanner values which not functional me.
the code needs run when:
search_code
entered manually ( keyboard ) andinsert_code
filled automatically barcode scanner
var search_code = document.getelementbyid('search_code'); var insert_code = document.getelementbyid('insert_code'); var result = document.getelementbyid('result'); var button = document.getelementbyid('button'); var audio = new audio('sound.wav'); // respond button click button.onclick = function validate(e) { e.preventdefault(); // show verification result: if (search_code.value == insert_code.value) { result.textcontent = 'code ok'; result.classname = "ok"; audio.play(); } else { result.textcontent = 'code not ok'; result.classname = "not-ok"; } // clear input when wrong: if (search_code.value !== insert_code.value) { insert_code.value = ''; } return false; }; function clearfield(input) { input.value = ""; };
.... <form> <input type="text" name="search_code" onfocus="clearfield(this, this.placeholder='');" onblur="this.placeholder='introdu codul'" id="search_code" placeholder="introdu codul" autocomplete="off" value=""/><br/> <input type="" name="insert_code" onfocus="clearfield(this, this.placeholder='');" onblur="this.placeholder='scaneaza codul'" id="insert_code" placeholder="scaneaza codul" autocomplete="off" value=""/><br/><br/> <input type="submit" id="button" name="button" value="verifica cod" /> </form> </div> <div id="result"></div> </div> <script src="js/action_input.js"></script> </body> </html>
thank you!
to prevent textbox
being filled bar-code reader disable onpaste
event .
$(document).ready(function(){ $('#search_code').bind("cut copy paste",function(e) { e.preventdefault(); }); });
Comments
Post a Comment