Domanda

Everything in my code works when i press enter on a form, the function executes correctly... However, when i press enter on the auto complete portion of the form, nothing whatsoever happens, and so i have to press enter again for it to activate...

Heres my code:

var element = document.getElementById("form");
element.addEventListener("keydown", dothis, false);

and the function:

function dothis(e){ 
  if(e.keyCode==13){  
    alert('yey');
  }
}

Is there anyway for this to work??

È stato utile?

Soluzione

Add an "onKeyUp" listener as well to take care of whatever is not getting handled the first time you press Enter:

element.addEventListener("keyup", dothat, false);

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top