Sunday, January 24, 2010

In an HTML form, how can I control which submit button is submitted when a user presses the return key?

%26lt;form%26gt;


%26lt;input type=';text'; name=';foo'; value=';123'; tabindex=';1'; /%26gt;



%26lt;input name=';commit'; tabindex=';3'; value=';CANCEL'; type=';submit'; /%26gt;



%26lt;input name=';commit'; tabindex=';2'; value=';NEXT'; type=';submit'; /%26gt;


%26lt;/form%26gt;





Visually, I prefer to have the cancel button above. Unfortunately, when a user hits return the cancel button gets submitted.





Thanks!In an HTML form, how can I control which submit button is submitted when a user presses the return key?
Change the 'CANCEL' button from type=';submit'; to type=';reset';. When this button is clicked, all inputs in the form will be reseted to the initial values (any input that user entered will be reverted).





Or if you want it to go forward user to the previous page instead:


%26lt;input name=';commit'; tabindex=';3'; value=';CANCEL'; type=';button'; onclick=';window.history.back();'; /%26gt;In an HTML form, how can I control which submit button is submitted when a user presses the return key?
Here is some code I've got running on my website. This is the html version, I've got PHP running the html . I don't think I deleted any html when removing the PHP!!!





%26lt;form method=';POST'; action=';saveticket.php';%26gt;


%26lt;p align=';center';%26gt;%26lt;tr%26gt;


%26lt;td width=';17%';%26gt;%26lt;input type=';submit'; name=';Submit'; value=';Submit';%26gt;%26lt;/td%26gt;


聽聽聽聽聽聽


%26lt;td width=';53%';%26gt;%26lt;input type=';reset'; name=';Reset'; value=';Clear Form';%26gt;%26lt;/td%26gt;


%26lt;/tr%26gt;%26lt;/p%26gt;


%26lt;/form%26gt;





%26lt;form method=';GET'; ACTION=';userz.htm';%26gt;


%26lt;tr%26gt;


%26lt;td%26gt;%26lt;p align=';center';%26gt;


%26lt;a href=';http://blah blah blah';%26gt;%26lt;input type=';submit'; name=';Submit'; value=';Cancel/Done';%26gt;%26lt;/a%26gt;%26lt;/p%26gt;


%26lt;/td%26gt;%26lt;/tr%26gt;


%26lt;/form%26gt;

No comments:

Post a Comment