Jump to content

Archived

This topic is now archived and is closed to further replies.

Xurion

So, i have a form...

Recommended Posts

I'm trying to make a form that submits when you press the enter/return key. When I have so far is 4 random numbers that display images on a page. The user must input the correct number shown and press the submit button. Done correctly this tells you have have done it right, but it only seems to submit if you click the button, and seems to refresh the page when you press the enter/return key.

If you wana see the example i have uploaded it is it http://www.xurion.co.uk/php/strrchr.php

Thx in advance.

Xur

Share this post


Link to post
Share on other sites
this is happening because the browser focus is probably on the url bar of your browser, so when you press enter, it's like typing in the url again and pressing enter.  if you press tab, it changes the focus to the next element of the browser, i.e.- the field where you enter in the number, the submit button, etc... you can possibly resolve this with javascript. i'm not sure if you can automatically give a certain element focus right off the bat (like your submit button), but you certainly can't do it with php.  and even if you could, the user could simply press tab or click on a different element and the submit button loses its focus. 

i'm moving this to the javascript forum.

Share this post


Link to post
Share on other sites
*sigh* lol moved twice now...

Anyways, if you type the number and hit enter/return it just refreshes... This does not have the focus in the URL

Share this post


Link to post
Share on other sites
well if the focus is in one of the inputs, when you click on enter it should automaticaly submit the form. You don't need to write extra code for that. If that's a text area things change, but on a simple password or text input enter button submits it. If the submit button is in the from element. Enter should work. At least it works in all of the sites I seen. I just write my username press tab then write my password then press enter :) No extra code is required :)

At least I think of course :)

Share this post


Link to post
Share on other sites
[quote author=radalin link=topic=105304.msg420577#msg420577 date=1156332286]
well if the focus is in one of the inputs, when you click on enter it should automaticaly submit the form. You don't need to write extra code for that. If that's a text area things change, but on a simple password or text input enter button submits it. If the submit button is in the from element. Enter should work. At least it works in all of the sites I seen. I just write my username press tab then write my password then press enter :) No extra code is required :)

At least I think of course :)
[/quote]
This is what I thought. can you have a look at the sources from the link I supplied earlier and see if there is anything wrong... I don't see anything wrong but it would be good to get a second person's opinion.

Thx again

Share this post


Link to post
Share on other sites
Well in my FF the enter works. and I see the correct images thing. It also works in my IE but instead of correct images I see more numbers to enter.

But enter button submit works.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.