Wednesday, September 23, 2009

HTML default buttons

I had been having a difficult time at work with a supposedly simple problem. I have a series of buttons in a web application, basically a "Previous", "Save & Exit", and "Next" button to guide the user of the web application through a wizard type application. The elements were declared as <>, not <>, because I wanted the customer to be able to customize the button layout and potentially use image buttons.

For the life of me, IE wanted to make the default button the first one and I couldn't override it to the "Next" button. At first what I had was a hack that I thought pretty much always worked.... Do a hidden <> tag with type=submit, then make that apply whatever button you wanted as the default... works great in Firefox but not in IE. So I tried making the "Next" an actual <> just to see if that functionality worked in IE. I set the type=submit, and the other buttons were still <>.... Still no dice and this time it broke Firefox, too! Google'ing around you get all sorts of weird suggestions like trying to trap the enter key and then firing an event. That borders on keylogger-ish behavior and some browsers and/or plugins might not allow that to work, just seemed like a big hack, too.

Final solution... specify type on BOTH buttons made through <> and <>... I was able to go back to making all 3 buttons a <> (therefore allowing image button support). On the default button, set type=submit. On ALL the other buttons (and this is the key), set type=button..... Now my rant...... why the heck would NORMAL non-attributed BUTTONS take precedence over anything that had a type=submit?!?!

No comments:

Post a Comment