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
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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.