Sunday, April 26, 2015

Prevent Enter Click on Text Box using Java Script

When ever in your html if you click Enter key on a text box after typing your text the very next submit button is being hit automatically. Now not every time it causes problems but few times it creates an serious issue to the application.
So how to prevent this issue? With java script we can handle this very easily. Lets see how to do so?

Into a notepad document write down this line.

<input type='text' onkeydown="return (event.keyCode!=13);"/>

onkeydown="return (event.keyCode!=13);" 

This is the main code to prevent the Enter press within the textbox. 

Note: ASCII key of ENTER is 13.

Now save your document, run it in browser and check.

On line demo:


Post a Comment

Popular Posts