MiloŇ° MiloŇ° - 5 months ago 70
HTML Question

HTML Text Input: Avoid submit when enter is pressed

I have an HTML input which is a textfield.
When I am pressing the enter, this will call the submit, which is normal.

Now, I would like to do something else when Enter is clicked on that textBox.

I am trying something like that:

<input type="text"
onkeydown="if (event.keyCode == 13) alert('enter')" />

The alert works well but the submit is still done. My page is reloading after that.

Could you help me please.

Answer Source

write return false; and check it

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download