Skip to content

Instantly share code, notes, and snippets.

@kamranayub
Created May 19, 2011 18:07
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save kamranayub/981360 to your computer and use it in GitHub Desktop.
Save kamranayub/981360 to your computer and use it in GitHub Desktop.
IE 7 and below <button> tag value on POST fix
$(function () {
//
// 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[name][value]").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 same name?
// As far as I know, it doesn't seem necessary
});
}
}
});
@Nowaker
Copy link

Nowaker commented Mar 1, 2012

This is how my GET looks like &ie_means=Get+quotation&means=Get+quotation - working on my fork to fix it.

@Nowaker
Copy link

Nowaker commented Mar 1, 2012

That's really strange. JQuery is not able to retrieve the $this.attr("value") in IE 7. The solution: http://stackoverflow.com/a/1863867/504845

@Nowaker
Copy link

Nowaker commented Mar 1, 2012

OK, done, see my version: https://gist.github.com/1949690

@kamranayub
Copy link
Author

It says in JQuery 1.6+ this should be fixed; what version are you using? I think it is working fine for us (since we use it for determining MVC actions).

@Nowaker
Copy link

Nowaker commented Mar 1, 2012

I see JQuery 1.3 in our ancient project... :-) I didn't think of checking the JQuery version. Anyway, I wouldn't update it, too much fear.

@Patrick64
Copy link

This works like a charm, cheers!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment