3

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.

GEOCHET
  • 21,119
  • 15
  • 74
  • 98

6 Answers6

6

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.

Mark Hurd
  • 13,010
  • 2
  • 27
  • 28
2

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.

Dan Lew
  • 85,990
  • 32
  • 182
  • 176
1

It's not a good idea. You point out the reason yourself - it doesn't work in all browsers. Also, it's not what people expect, so it may confuse people.

Khoth
  • 13,068
  • 3
  • 28
  • 27
0

It depends on what you mean with "ok".

If you mean valid (x)html, well it's no problem at all, but on the user side, it's a usability issue. But it also depends on the target audience of your website. If its for tech savvy people, then it's ok.

You could create an input button like this:

<input type="button" onclick("doSomething()") />

The doSomething() would be a function in Javascript that would send your form data to a server-side script. This way you wouldn't have a submit behavior.

rogeriopvl
  • 51,659
  • 8
  • 55
  • 58
0

Submitting a form on 'Enter' with jQuery?

Also, I'd leave the button in the form, but hide it with javascript ($('#submit').hide()). It means that if the user has disabled script or f.ex. uses some other device, he'll see the default way to submit the form.

Community
  • 1
  • 1
zalew
  • 10,171
  • 3
  • 29
  • 32
-1

If you want to have two buttons which generate two different behavior when submit. what you can so is something like that:

or you can put the form submit inside function1() or function2()

Murvinlai
  • 2,276
  • 6
  • 23
  • 34