Alex Rivera | Logout

Prevent form submission on Enter key press

Asked 2009-05-25T03:31:28.980
381

I have a form with two text boxes, one select drop down and one radio button. When the enter key is pressed, I want to call my JavaScript function, but when I press it, the form is submitted.

How do I prevent the form from being submitted when the enter key is pressed?

Edit
Report

1 Answer

18

Override the onsubmit action of the form to be a call to your function and add return false after it, ie:

<form onsubmit="javascript:myfunc();return false;" >
answered 2009-05-25T03:40:51.813

Your Answer