CarlosAllende
CarlosAllende

Reputation: 292

Adding a form input breaks form

Right now I have a form with one input and one textarea, and I am trying to add an input, however when I do it causes the form to not submit, I am submitting by hitting the enter key and not using a button.

Current code:

<form method="POST">
Suggestion Subject: <input class="login-input" name="subject"><br> 
Suggestion: 
<textarea class="login-input" rows="8" name="suggestion"></textarea><br>
Username: 
<input class="login-input" type="text" name="name"><br>
Hit the Enter key to submit your suggestion
</form>

When I add the Suggestion Subject input, it can no longer be submitted. Any idea why?

Upvotes: 0

Views: 136

Answers (2)

nweg
nweg

Reputation: 2865

Add type="text" to your subject field, like so:

<input class="login-input" type="text" name="subject">

and add a submit button like so (this will hide in all browsers):

<input type="submit" style="position: absolute; left: -9999px; width: 1px; height: 1px;"/>

Upvotes: 0

j08691
j08691

Reputation: 207901

The default behavior of a HTML form with a single input field is to submit the form on pressing enter on that field. Once you add more text inputs, pressing enter will no longer submit the form. To submit the form via enter, you'll need to add a submit button. If you don't want to see the button you can hide it.

Upvotes: 2

Related Questions