Click here to get back home

Multiple form submit buttons - setting a default button

 HomeNewsGroups | Search | About
 comp.infosystems.www.authoring.html    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
Multiple form submit buttons - setting a default button Stanimir Stamenkov 03-19-2008
Posted by Stanimir Stamenkov on March 19, 2008, 4:03 am
Please log in for more thread options
Is there a way to specify a default submit button in case there are
more than one in a form? That is, to specify which button will be
triggered as default action when pressing Enter in a form field.

Currently I observe only the first submit button appearing in the
document order is triggered:

<form action="">
<div>
<label>Field 1: <input type="text" name="field1"></label></div>
<div>
<label>Field 2: <input type="text" name="field2"></label></div>
<div>
<input type="submit" name="operation" value="Create">
<input type="submit" name="operation" value="Update">
<input type="submit" name="operation" value="Delete"></div>
</form>

--
Stanimir

Posted by Jukka K. Korpela on March 19, 2008, 7:26 am
Please log in for more thread options
Scripsit Stanimir Stamenkov:

> Is there a way to specify a default submit button in case there are
> more than one in a form?

No.

> That is, to specify which button will be
> triggered as default action when pressing Enter in a form field.

The original idea was to allow quick submission of a form in a very
simple case where a form has just one text input field and possibly
checkboxes or radio buttons. Things were messed up by extending this, in
some browsers, to cases where it is far from obvious what pressing Enter
_should_ mean.

So now it's largely a problem rather than a convenience. For any form
with more than one input field, there is a risk of submissio praecox:
the user types in his name and hits Enter (accidentally or maybe because
he is used to some form systems where Enter takes to the next field),
and then you a person's name and nothing else. Well, you might have nice
defaults in the form so that the form data says that he just ordered a
dozen used cars from you, but this won't hold in court, I'm afraid.

> Currently I observe only the first submit button appearing in the
> document order is triggered:

That's the usual scenario in browsers that support the convoluted idea.
It's probably not documented anywhere, and surely not in HTML
specifications.

> <div>
> <input type="submit" name="operation" value="Create">
> <input type="submit" name="operation" value="Update">
> <input type="submit" name="operation" value="Delete"></div>

Instead of this, use a set of radio buttons and a single submit button:

<fieldset>
<legend>Action</legend>
<div><label><input type="radio" name="operation"
value="Create">Create</label></div>
<div><label><input type="radio" name="operation"
value="Update">Update</label></div>
<div><label><input type="radio" name="operation"
value="Delete">Delete</label></div>
<div><label><input type="radio" name="operation"
value="" checked>No action selected yet</label></div>
<div><input type="submit" value="Do it"></div>
</fieldset>

There's still the risk that the user types in the first text input field
and hits Enter, but in practice this means that the "operation" field in
form data is empty and you can detect the situation. The you can just
tell the user that the data is incomplete and send back the page with
the filled-in data as prefilled, to be completed and resubmitted.

--
Jukka K. Korpela ("Yucca")
http://www.cs.tut.fi/~jkorpela/


Posted by Beauregard T. Shagnasty on March 19, 2008, 9:10 am
Please log in for more thread options
Jukka K. Korpela wrote:

> Scripsit Stanimir Stamenkov:
>> Is there a way to specify a default submit button in case there are
>> more than one in a form?
>
> No.
> ...
>> <div>
>> <input type="submit" name="operation" value="Create">
>> <input type="submit" name="operation" value="Update">
>> <input type="submit" name="operation" value="Delete"></div>
>
> Instead of this, use a set of radio buttons and a single submit button:

Similar to this.
http://k75s.home.att.net/show/radio.jpg

(a sample I use on a small, custom CMS. In this case the records, small
in number, are displayed in a table above the radio buttons.)

--
-bts
-Friends don't let friends drive Vista

Posted by Petr Vileta on March 19, 2008, 11:29 pm
Please log in for more thread options
Stanimir Stamenkov wrote:
> Is there a way to specify a default submit button in case there are
> more than one in a form? That is, to specify which button will be
> triggered as default action when pressing Enter in a form field.
>
> Currently I observe only the first submit button appearing in the
> document order is triggered:
>
> <form action="">
> <div>
> <label>Field 1: <input type="text" name="field1"></label></div>
> <div>
> <label>Field 2: <input type="text" name="field2"></label></div>
> <div>
> <input type="submit" name="operation" value="Create">
> <input type="submit" name="operation" value="Update">
> <input type="submit" name="operation" value="Delete"></div>
> </form>

Maybe somebody correct me but in many cases (and browsers) a default button is
a first one. In other word if I have a form with some text inputs and two
submit buttons called "Yes" and "No" and I want the "No" will be default then
I place "No" buttone before "Yes". This solution is not 100% secure but work
in most cases.
--
Petr Vileta, Czech republic
(My server rejects all messages from Yahoo and Hotmail. Send me your
mail from another non-spammer site please.)

Please reply to <petr AT practisoft DOT cz>


Similar ThreadsPosted
Using multiple button type="submit" elements within a form April 15, 2005, 4:24 pm
Multiple submit buttons problem August 18, 2006, 6:46 am
Having no default button in a form August 24, 2005, 3:41 am
Submit a form without using a button? December 24, 2004, 4:26 pm
How to get rid of focus on submit button of a form. September 5, 2004, 1:21 pm
Newbie: How to use graphic instead of submit button on HTML form? August 29, 2006, 5:57 am
more submit buttons problem November 6, 2008, 11:31 am
Multiple groups of radio buttons with same name? September 30, 2004, 7:32 am
Default type of July 1, 2005, 9:01 pm
CSS submit button problem March 17, 2005, 1:08 pm

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap