Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reading in a keystroke using javascript

Status
Not open for further replies.

skills

Programmer
Jun 24, 2003
60
US
Is it possible to have javascript look for a keystroke, and if the key is pressed, then do something?

Skills
 
Yes, in IE, there is event.keyCode and in Netscape there is (I think... I'm trying to remember from my text which is not with me) event.type or something. I usually use this to check for when a user hits the enter key:

Code:
function checkEnter(evt, field)
{
 if(event.keyCode == 13)
  doSomething();
}

I'm typing this from memory. See the tail end of the discussion at the following link for a better-informed explanation:

thread216-617648 luck.

--Dave
 
Do DEFINITELY follow the above link as I got the function wrong above. It should be:

Code:
function checkEnter(field, evt)
{
 if(event.keyCode == 13)    //enter
  form1.submit();
}

Good luck.

-Dave
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top