Reputation: 11
Internet Explorer 7 does not handle buttons correctly since it sends the text between <button>
and </button>
rather than the value. (Weird but true.) This Javascript is supposed to correct this by sending the value of the button onClick
. But it does not work. Can anybody see the error ?
I use this to attach the Javascript file in HTML5 :
<script src="buttonfix.js"></script>
Contents of buttonfix.js :
function runonclick()
{
var count = 0;
var formlength = this.form.elements.length;
while(count < formlength)
{
if(this.form.elements[count].tagName === "button")
{
this.value = this.attributes.getNamedItem("value").nodeValue;
}
count++;
}
}
function buttonfix()
{
var buttonarray = document.getElementsByTagName("button");
var count = 0;
var buttonarraylength = buttonarray.length;
while(count < buttonarraylength)
{
buttonarray[count].onClick = runonclick();
count++;
}
}
window.attachEvent("onload", buttonfix());
Upvotes: 1
Views: 219
Reputation: 5857
I suggest you to try:
if(this.form.elements[count].tagName.toLowerCase == "button");
instead of:
if(this.form.elements[count].tagName == "button")
because the tagName
property generally returns an uppercased string.
Another line does not work:
buttonarray[count].onClick = runonclick();
As JavaScript it is a case-sensitive language, you have to use the standard name of the event (onclick
).
buttonarray[count].onclick = runonclick();
However, you may still to use onClick
in your HTML (but not XHTML).
Upvotes: 1