Submit by hitting enter not clicking the button

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
scubadiveflorida
Forum Newbie
Posts: 10
Joined: Wed Oct 29, 2003 9:53 am

Submit by hitting enter not clicking the button

Post 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.
mlitton
Forum Newbie
Posts: 11
Joined: Sun Sep 21, 2003 4:52 pm
Location: Sweden

Post by mlitton »

Do you have more than one button on the page? Otherwise it should just work.

-- mike
microthick
Forum Regular
Posts: 543
Joined: Wed Sep 24, 2003 2:15 pm
Location: Vancouver, BC

Re: Submit by hitting enter not clicking the button

Post 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.
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post 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
Post Reply