Skip to content

Instantly share code, notes, and snippets.

@dkln
Created December 20, 2010 10:36
Show Gist options
  • Save dkln/748237 to your computer and use it in GitHub Desktop.
Save dkln/748237 to your computer and use it in GitHub Desktop.
Makes buttons behave normally in IE7
function buttonfix() {
var buttons = document.getElementsByTagName('button');
for (var i=0; i < buttons.length; i++) {
if (buttons[i].onclick) { continue; }
buttons[i].onclick = function () {
for (j=0; j<this.form.elements.length; j++) {
if (this.form.elements[j].tagName == 'BUTTON') {
this.form.elements[j].disabled = true;
}
}
this.disabled = false;
var input = document.createElement('input');
input.setAttribute('name', this.name);
input.setAttribute('value', this.attributes.getNamedItem('value').nodeValue);
input.setAttribute('type', 'hidden');
this.form.appendChild(input);
this.name = '';
}
}
}
window.attachEvent("onload", buttonfix);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment