Jump to content

So, i have a form...


Xurion

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
Link to comment
https://forums.phpfreaks.com/topic/18394-so-i-have-a-form/
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.
Link to comment
https://forums.phpfreaks.com/topic/18394-so-i-have-a-form/#findComment-79079
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 :)
Link to comment
https://forums.phpfreaks.com/topic/18394-so-i-have-a-form/#findComment-79108
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
Link to comment
https://forums.phpfreaks.com/topic/18394-so-i-have-a-form/#findComment-79138
Share on other sites

Archived

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

×
×
  • Create New...

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.