solution for On “Enter Key” press event in javascript

Hello guys,
while working on a project i needed to add a text input which takes some action when the user press on the “enter key”, you know it’s something like facebook comment text input 😉

as you may know there is no “onenterkey” or “onsubmit” for the text input. I stayed 15 min. trying to get the job done but in vain. That got me mad that i was talking to the text input “hey you mr. input how the hell you get that event fired ?!!!!!!”. finally i got a trick.

Here’s a little trick that may help.

you can use the “onkeydown” event and then check the pressed key if the key code is 13 “actually is the enter key code”. you can get the key code with that command “event.keyCode”

As you can see it seen a little snippet but it got me out of that problem 😀

Here’s a snippet that can demonstrate what i’m talking about

<input type="text" onkeydown="if (event.keyCode == 13) doSomeThing(paam1 , param2.....);" >

Hope you’ve enjoyed
Thanks 🙂