2

I am working on a somewhat lengthy program. The program works almost perfectly, except for one thing: when I press the Enter key while I am clicked in the text box, it automatically clears the box and appends the data to the URL, like with a GET request. I simplified this program greatly to give this:

<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>Simple Version</title>
    </head>
    <body>
        <form>
            <input type="text" name="password"/>
        </form>
    </body>
</html>

This happens on the two Windows 7 machines I tried, in Chrome, IE, and Firefox.

I would appreciate it if someone explained a way to prevent this.

alexwho314
  • 29
  • 2
  • 9
  • 1
    The default method for form is GET, When you hit enter, the form is submitted, since you didn't specify the method and the action, it is being submitted to it self using GET. When the form is using GET, the parameter name is appended to the query string. This is behaving as it is supposed to be. I guess the question is, what are you trying to do? – atbebtg Jun 24 '13 at 18:08
  • @atbebtg, thank you. I did not set a method or action because I am making an AJAX application, which would not work with those parameters, as far as I know. The only way I've been able to get around that so far is to remove the `
    ` tag, but I feel that because it's a form I should still use it.
    – alexwho314 Jun 24 '13 at 18:15
  • if you are going to submit the data using ajax take a look at the following post. You can disable the form from being submitted http://stackoverflow.com/questions/895171/prevent-users-from-submitting-form-by-hitting-enter – atbebtg Jun 24 '13 at 18:20
  • Can I post that as an answer and have you mark it as the correct answer? – atbebtg Jun 24 '13 at 18:34
  • @atbebtg, that would be helpful. – alexwho314 Jun 24 '13 at 18:47

1 Answers1

2

The default method for form is GET, When you hit enter, the form is submitted, since you didn't specify the method and the action, it is being submitted to it self using GET. When the form is using GET, the parameter name is appended to the query string. This is behaving as it is supposed to be.

if you are going to submit the data using ajax take a look at the following post. You can disable the form from being submitted Prevent users from submitting a form by hitting Enter

Community
  • 1
  • 1
atbebtg
  • 4,023
  • 9
  • 37
  • 49