Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Single text box and submit behaviour

I have a single text box with no submit button on form as below :

<html>
    <form action="http://www.google.com">
        <input type="text"/>
    </form>
</html>

when text box is selected and i press enter key form will get submitted and google page will be displayed. however if i have two text box as bellow :

<html>
    <form action="http://www.google.com">
        <input type="text"/>
        <input type="text"/>
    </form>
</html>

now if i press submit button nothing will happen.

Can anyone explain here :
i) why form is get submitted in first case?
ii) why form is not submitting in second case?

like image 230
Vipul Avatar asked Apr 26 '12 09:04

Vipul


1 Answers

HTML 2.0 Specs:

When there is only one single-line text input field in a form, the user agent should accept Enter in that field as a request to submit the form.

The easiest way to disable this behavior is to add a hidden input field.

like image 144
Till Avatar answered Oct 13 '22 07:10

Till