Friday, June 17, 2005

HTML form trick

Sometimes you come up with something so simple and so useful you have to share.

So ... I'm working on a Wizard and I have four buttons across the bottom of the form: "< Previous", "Next >", "Finish >>" and "Cancel".

But I noticed that when I hit the return key inside on of the fields of the form, it kept acting like "< Previous" was clicked. That's not what I wanted at all.

The browser basically worked forward in the tab order from the text field I clicked until it found as submit button within the form ... which happened to be "< Previous".

My solution?

<input type="submit" style="display: none"/>

That empty submit gets "found" (desipite being invisible) before the "< Previous" button, and the form submits normally.

2 comments:

  1. Wouter Cleuren also posted this to the user list last week. Why are all the bright minds solving this problem now, instead of months ago when people were asking for solutions? ;-)

    I've been using gstamp's ButtonSubmit combined with an invisible ImageSubmit, but will change to the invisible Submit if it covers all cases.

    ReplyDelete
  2. http://www.thescripts.com/forum/thread622606.html

    Tells you how to do this, basically

    protected void Page_Load(object sender, EventArgs e)
    {
    Button1.UseSubmitBehavior = false;
    Button2.UseSubmitBehavior = true;

    Page.Form.DefaultFocus = Button2.ClientID;
    }

    ReplyDelete

Please note that this is not a support forum for Tapestry. Requests for help will be deleted. Please subscribe to the Tapestry user mailing list if you are in need of support, or contact me directly for professional (for pay) support.

Spammers: Don't bother. I delete your comments and it's a waste of time for both of us. 垃圾邮件发送者:不要打扰。我删除您的评论和它的时间对我们双方的浪费