javascript - Google App Script - Enter key in input textbox - how to catch or disable? -


i have html page published web app through google app scripts. on page input box (textbox) user types number search for. if click 'search' button beside box, works fine. if type number , press 'enter' on keyboard, throws 400 error ('the requested url not found on server. ').

input area code:

<input type="text" id="claimsearchbox" class="form-control"  placeholder="search" /> <input type="button" id="btnsearchclaims" class="btn-md btn-success" onclick="getorders" value="search claim"  /> 

javascript: (this works button)

document.getelementbyid("btnsearchclaims").addeventlistener("click", getorders); 

(this not work input box)

document.getelementbyid("claimsearchbox").addeventlistener("keyup", function(event) { event.preventdefault(); console.log('event:  ' + event.keycode); if (event.keycode == 13) {   console.log('correct key');   getorders(); } }); 

i tried this, shows keys pressed, press enter, goes 400 error.

$(document).ready(function(){   $("claimsearchbox").keyup(function(e){   console.log(e.keycode);     console.log("worked");    }); }); 

any suggestions? there way disable 'enter' if can't redirect getorders()?

**edited add...if don't have programming input box , user presses enter - goes error (page blank - error shown in console).

***found problem: turns out issue of input box being input box on form. when user hits enter, automatically submits form! found issue/solution here: why forms single input field submit upon pressing enter key in input

this may further code.

i see invoking jquery.

$(document).ready(function(){ 

can confirm page displaying loading jquery?

your html should have present.

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> 

if use debugger , enter readythen have jquery loaded.

with jquery, simplify event handling.

replace

document.getelementbyid("btnsearchclaims").addeventlistener("click", getorders); 

with

$("#btnsearchclaims").on("click", getorders); 

replace

document.getelementbyid("claimsearchbox").addeventlistener("keyup",  function(event) { 

with

$("#claimsearchbox").on("keyup", function(event)... 

Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -