Click to See Complete Forum and Search --> : put "enter"


vinsa
04-12-2003, 12:16 PM
Hello,
first sorry for my English.
I need from javascript.
I want, when I put the button "enter"
on keyboard to activate my function in
my javascript. How can I do that?

Nevermore
04-12-2003, 12:40 PM
This function will trigger the function when enter is pressed:

function Key(e) {
if (e.keyCode) keycode=e.keyCode;
else keycode=e.which;
if(keycode=="13") //insert function here }

and you should also place the code:

onKeyPress="Key(event);"

in the body tag.

Jona
04-12-2003, 12:42 PM
For IE:

<html><head>
<script>
function execOnEnter(){
if(event.keyPress=="13"){yourFunctionName();}
else{return false;}
}
document.onkeypress=execOnEnter;
</script></head>
<body>

Your page

</body></html>

Jona
04-12-2003, 12:44 PM
Oops! I goofed. I forgot to put Netscape in there.... :p Hey, give me a break... I don't have Netscape on this computer. Oh well, I gave it a shot. :)

Nevermore
04-13-2003, 06:24 AM
My solution should run in Netscape

David Harrison
04-13-2003, 09:38 AM
How do you know which keypress's or keycode's do what?

Nevermore
04-13-2003, 10:42 AM
I created a JavaScript which will give the keycode for most actions, although not all. http://www32.brinkster.com/jjscripts/keycodefinder.html

David Harrison
04-13-2003, 12:25 PM
Thanks