Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML form submission with no submit button

I've got a form like this:

<html> 
    <body> 
        <form onSubmit="alert('Just got submitted');">
            <p>
            Hello: <input class="field" type="text"/><br/>
            Goodbye: <input class="field" type="text"/><br/>
            </p>
        </form>
    </body> 
</html> 

which in one browser submits happily on user pressing enter from one of the fields, and in another browser, doesn't. Oddly, if I remove the second field, it works in both.

My question is really - is it okay to have a form with no explicit submit element? I really like this behaviour.


2 Answers

Having no explicit submit is poor user experience. Your typical end user has, over the past decade, learned a set of principles for website form interaction. Namely, you can tab between fields, you can select lots of checkboxes, and you have a click a button to actually submit your data.

I've tried developing forms in the past that automatically update with JavaScript, and I got countless complaints from users. They wanted a button or they didn't believe it was working. So in that particular case, I kept the form working as it originally had, but added a submit button that really didn't do anything. They were happy.

These days I just build out my forms with normal submit buttons. Not only do users expect it, but it allows for much cleaner progressive enhancement between non-JS enabled browsers.

like image 143
Mark Hurd Avatar answered Apr 10 '26 06:04

Mark Hurd


It's certainly more than possible to have a form with no submit element, especially if you use JavaScript events to submit the form. I highly suggest you use the onkeypress event to detect the "enter" key being pressed rather than depending on the browser to just accept the "enter" key if you make a form with no submits, to make it cross-browser compatible.

However, I think it's bad form to leave out a submit button of some sort. (It doesn't necessarily have to be an input of type "submit", could be "button" or an image you click.) It's just a standard to have forms that people fill out submitt via a button, and you're taking that away, which could confuse many users who are used to a button. It definitely violates the principles of Don't Make Me Think by presenting an alternate form to the norm.

like image 33
Dan Lew Avatar answered Apr 10 '26 07:04

Dan Lew