alexwho314
alexwho314

Reputation: 41

HTML Text Input Box Is Cleared On Enter

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.

Upvotes: 3

Views: 4649

Answers (1)

atbebtg
atbebtg

Reputation: 4083

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

Upvotes: 2

Related Questions