javascript - I want to add keyup and click on a button -
whenever user press or click button #btnsubmit ajax executes. when press enter. both keyup , click executes.
when use click. executes click function.
<script type="text/javascript"> function loaddelegates($barcode) { var xhttp = new xmlhttprequest(); xhttp.onreadystatechange = function() { if (this.readystate == 4 && this.status == 200) { document.getelementbyid("getdel").innerhtml = this.responsetext; $("#btnsubmit").focus(); } }; xhttp.open("get", "activityclient/" + $barcode, true); xhttp.send(); } function storetime($barcode) { var xhttp = new xmlhttprequest(); xhttp.onreadystatechange = function() { if (this.readystate == 4 && this.status == 200) { document.getelementbyid("getdel").innerhtml = this.responsetext; $("#barcode").focus().select(); } }; xhttp.open("get", "activityclient/" + $barcode + "/store", true); xhttp.send(); } $(function() { $(document).on('keyup','#barcode',function(e) { e.preventdefault(); var code = e.keycode || e.which; if (code == 13 && $(this).val().length >= 1) { loaddelegates($(this).val()); return false; } }); $(document).on('keyup','#btnsubmit',function(e) { e.preventdefault(); var code = e.keycode || e.which; if (code == 13) { var barcode = document.getelementbyid('barcode').value; storetime(barcode); return false; } }); $(document).on('click','#btnsubmit',function() { var barcode = document.getelementbyid('barcode').value; storetime(barcode); return false; }); });
thank you
you don't need add event handler enter key. remove , should work.
Comments
Post a Comment