Javascript web browser script not working

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Jana Winchester
    New Member
    • Jun 2011
    • 1

    Javascript web browser script not working

    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 :

    Code:
    <script src="buttonfix.js"></script>
    Contents of buttonfix.js :

    [code=javascript]
    function runonclick()
    {
    var count = 0;
    var formlength = this.form.eleme nts.length;
    while(count < formlength)
    {
    if(this.form.el ements[count].tagName.toLowe rCase() == "button")
    {
    this.value = this.attributes .getNamedItem(" value").nodeVal ue;
    }

    count++;
    }
    }

    function buttonfix()
    {
    var buttonarray = document.getEle mentsByTagName( "button");

    var count = 0;
    var buttonarrayleng th = buttonarray.len gth;
    while(count < buttonarrayleng th)
    {
    buttonarray[count].onclick = runonclick;

    count++;
    }
    }

    window.attachEv ent("onload", buttonfix);
    [/code]
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    Internet Explorer 7 does not handle buttons correctly since it sends the text between <button> and </button>rather than the value.
    which is exactly what it is supposed to do, since the <button> element does not have a value attribute (compare to <textarea>).

    Comment

    Working...