HighDots Forums  

Multiple form submit buttons - setting a default button

HTML Writing HTML for the Web (comp.infosystems.www.authoring.html)


Discuss Multiple form submit buttons - setting a default button in the HTML forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Stanimir Stamenkov
 
Posts: n/a

Default Multiple form submit buttons - setting a default button - 03-19-2008 , 03:03 AM






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

Reply With Quote
  #2  
Old   
Jukka K. Korpela
 
Posts: n/a

Default Re: Multiple form submit buttons - setting a default button - 03-19-2008 , 06:26 AM






Scripsit Stanimir Stamenkov:

Quote:
Is there a way to specify a default submit button in case there are
more than one in a form?
No.

Quote:
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.

Quote:
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.

Quote:
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/



Reply With Quote
  #3  
Old   
Petr Vileta
 
Posts: n/a

Default Re: Multiple form submit buttons - setting a default button - 03-19-2008 , 10:29 PM



Stanimir Stamenkov wrote:
Quote:
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>



Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.