javascript - How to handle the ENTER keypressed to trigger an onBlur() event? -


i have ipad webapp big <form> @ point. every input in has functions controlling values, both on keyup , blur events.

thing is, if user accidentaly hits "go" button while typing (considered "enter" keypress), form submitted. intercept comportment , trigger onblur() event of focused element instead.

for have this:

load(){   document.addeventlistener("keydown",logpressedkeys,false); } /**  * logs keys hit in console, trigger onblur event  */   function logpressedkeys(e) {       console.log(e.keycode);       if (e.keycode==13) {       console.log('enter spotted: prevent!');       e.preventdefault();//shall prevent submitting       return false;//hoping prevents default if above fails   } } 

do guys have advice/idea/improvement that?

nota bene: there has @ least 1 input focused ipad's keyboard pop.

found out document.activeelement works out in ipad's safari.

function logpressedkeys(e) {     console.log(e.keycode);     if (e.keycode==13) {       e.preventdefault();       console.log('enter spotted: prevent!');       temp=document.activeelement;       //console.log(temp);       temp.onblur();       return false; } return true; } 

Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -