tags:

views:

105

answers:

2

I have a js event on enter keypress which works fine. But after that event it also submits the form which has a submit button. How do I stop that submit button from getting focus after the previous keypress event?

EDIT: I DONT WANT THE SUBMIT BUTTON TO SUBMIT ON ENTER, ONLY ON CLICK.

+1  A: 

Not sure if I understand correctly, but if you are trying to prevent the form from getting submitted:

Attach an onsubmit event and return false from it.

<form onsubmit="submit_handler();"></form>
[...]

function submit_handler()
{
    //do stuff
    return (false);
}
nc3b
WHat about the enter key stuff? He wants it to only submit with mouseclick, not enterkey
Maxim Zaslavsky
Yeah, I commented on his question.
nc3b
+1  A: 

Typically the answer to javascript questions of the type "How do I keep my form from submitting after I ...." is "make your javascript function return false".

JacobM
This will work. Although I strongly discourage non-standard behavior - unless you have a very good, very specific use case where this functionality just simply *must* be altered.
anonymous coward