Page 1 of 1

Submit by hitting enter not clicking the button

Posted: Thu Nov 20, 2003 12:04 pm
by scubadiveflorida
I have built a form and when you type in the data in the text field then click submit, it works fine. But... when I type in the data in the text field then hit enter it fails. Is there a way I can make enter do the same thing as clicking the submit button? Thanks.

Posted: Thu Nov 20, 2003 12:11 pm
by mlitton
Do you have more than one button on the page? Otherwise it should just work.

-- mike

Re: Submit by hitting enter not clicking the button

Posted: Thu Nov 20, 2003 12:21 pm
by microthick
scubadiveflorida wrote:I have built a form and when you type in the data in the text field then click submit, it works fine. But... when I type in the data in the text field then hit enter it fails. Is there a way I can make enter do the same thing as clicking the submit button? Thanks.
What exactly is failing?

If, on your action page, you are looking for say a value in $_POST["mysubmitbutton"], it'll come up as empty if you pressed ENTER.

If you just mean that ENTER fails to submit the form, then you can do this:

In the text field, you can add the attribute onKeyPress to run a JavaScript function that sees whether the key pressed was ENTER then if so, document.form.submit(). I don't have any script handy for this event handling.

Posted: Fri Nov 21, 2003 2:51 am
by twigletmac
You can also put a hidden field in the form and check whether that exists rather than the submit button. It gets around the problem of enter != submit button press on some browsers.

Mac