[whatwg] default action/button for forms

Matthew Raymond mattraymond at earthlink.net
Fri Feb 11 08:52:55 PST 2005

Michael Gratton wrote:
> After looking through the archives, surprised to find that there has
> been no mention of some way to specify the default button/action for a
> form.
> Most browsers behave as the Web Forms 2.0 spec specifies in section 2.3,
> "Changes to existing controls". That is, the first button is used as the
> default. But this is pretty annoying behaviour. In a large form, it is
> common to have several submit buttons and is is just as likely as it is
> not that the first button should be the default.

    Good point.

> As a result, web application developers generally resort to one of two
> kluges: adding a hidden submit button to the form or using JavaScript to
> trap key events or the form submission event.

    Neither ideal, since it's best to have solutions that don't CSS or 
JS support.


> It would be great to see some way of specifying the default button for
> the form in Web Forms 2.0, or some later revision. One way of
> implementing this (and the way I would do it if I was fixing the problem
> using JavaScript) would be to add a "default-action" attribute or
> similar to the form element. This would be an IDREF that specifies the
> id of the default submit button. Eg:
>   <form action="bofh" method="post" default-action="lart">
>     <input type="text" name="who">
>     <input type="submit" id="ignore" name="action" value="Ignore">
>     <input type="submit" id="lart" name="action" value="LART">
>   </form>
> What do you think?

    I'd prefer something like this:

| <form action="http://somesite.com/prog/adduser" method="post">
|   <input type="text" name="who">
|   <input type="submit" name="action" value="Remove">
|   <input default type="submit" name="action" value="Add">
| </form>

More information about the whatwg mailing list