views:

1192

answers:

7

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.

+6  A: 

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
+1  A: 

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
+1  A: 

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.

Daniel Lew
"... it's bad form ..." Ha ha! You're so punny. :)
Tyson
A: 

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
A: 

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
A: 

Two possibly useful articles:

Using the enter key to submit a form Submit Form on Enter Key

artlung
A: 

http://stackoverflow.com/questions/699065/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.

zalew