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 🙂

Advertisements

3 responses »

  1. Jan says:

    Thanks! great efficient solution! saves me creating submit buttons.

  2. Angelica says:

    hey guy you can not imagine how useful was this single line for me!!! I was also getting crazy 😉 trying to find a solution for what I wanted to do! :))

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s