Skip to content

Instantly share code, notes, and snippets.

@postpostmodern
Created December 8, 2009 00:22
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save postpostmodern/251287 to your computer and use it in GitHub Desktop.
Save postpostmodern/251287 to your computer and use it in GitHub Desktop.
// IE doesn't deal well with button elements.
// The following jQuery code fixes the two most common issues:
// 1. All button values being submitted whether they were clicked or not
// 2. Button labels being submitted instead of the value of the value attribute
// Make sure you have loaded jQuery, of course.
if ($.browser.msie) {
jQuery(function() {
$('form button[type=submit]').click(function() {
// Handle on the button clicked
var obj = $(this);
// Disable all buttons (keeps their values from being submitted)
$('button').attr('disabled', 'disabled');
// Get the text label of the button
var label = obj.text();
// Set it to an empty string so IE will read the real value attribute
obj.text('');
// Create a hidden field with the name and value of the button
obj.after($("<input/>").attr('type', 'hidden').attr('name', obj.attr('name')).val(obj.attr('value')));
// Restore the button's text label
obj.text(label);
// Submit the form
obj.closest('form').submit();
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment