Xurion Posted August 23, 2006 Share Posted August 23, 2006 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.phpThx in advance.Xur Quote Link to comment https://forums.phpfreaks.com/topic/18394-so-i-have-a-form/ Share on other sites More sharing options...
.josh Posted August 23, 2006 Share Posted August 23, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/18394-so-i-have-a-form/#findComment-79079 Share on other sites More sharing options...
Xurion Posted August 23, 2006 Author Share Posted August 23, 2006 *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 Quote Link to comment https://forums.phpfreaks.com/topic/18394-so-i-have-a-form/#findComment-79081 Share on other sites More sharing options...
radalin Posted August 23, 2006 Share Posted August 23, 2006 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 Link to comment https://forums.phpfreaks.com/topic/18394-so-i-have-a-form/#findComment-79108 Share on other sites More sharing options...
Xurion Posted August 23, 2006 Author Share Posted August 23, 2006 [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 Quote Link to comment https://forums.phpfreaks.com/topic/18394-so-i-have-a-form/#findComment-79138 Share on other sites More sharing options...
radalin Posted August 23, 2006 Share Posted August 23, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/18394-so-i-have-a-form/#findComment-79380 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.