So, I'm just doing this (an enhancement to Chileno's solution):
// // IE 7 and below <button> fix // See: http://www.peterbe.com/plog/button-tag-in-IE // if ($.browser.msie) { if ($.browser.version === "7.0" || $.browser.version === "6.0") { $("button").live('click', function () { var $this = $(this), name = $this.attr("name"), value = $this.attr("value");
// Assemble replacement hidden field, same name, same value $("<input type='hidden' />") .attr("name", name) .val(value) .insertAfter($this);
// Rename this field so IE doesn't overwrite value $this.attr("name", "ie_" + name);
// TODO: Do we need to rename any other buttons with the name name? // As far as I know, it doesn't seem necessary }); } }
On page load.
Prevents flashing the value of the button as the text of the button and seems to work great. I added a TODO in case someone runs into the issue, but I tested this with multiple "action" buttons and it works fine.
I use .live() in case of AJAX requests bringing back new buttons.
Comment
So, I'm just doing this (an enhancement to Chileno's solution):
//
// IE 7 and below <button> fix
// See: http://www.peterbe.com/plog/button-tag-in-IE
//
if ($.browser.msie) {
if ($.browser.version === "7.0" ||
$.browser.version === "6.0") {
$("button").live('click', function () {
var $this = $(this),
name = $this.attr("name"),
value = $this.attr("value");
// Assemble replacement hidden field, same name, same value
$("<input type='hidden' />")
.attr("name", name)
.val(value)
.insertAfter($this);
// Rename this field so IE doesn't overwrite value
$this.attr("name", "ie_" + name);
// TODO: Do we need to rename any other buttons with the name name?
// As far as I know, it doesn't seem necessary
});
}
}
On page load.
Prevents flashing the value of the button as the text of the button and seems to work great. I added a TODO in case someone runs into the issue, but I tested this with multiple "action" buttons and it works fine.
I use .live() in case of AJAX requests bringing back new buttons.
Replies
Posted a blog entry on it: http://kamranicus.com/Blog/Posts/9/fixing-the-post-value-of-the-button-element-in-ie