www.webdeveloper.com
Results 1 to 3 of 3

Thread: Javascript web browser script not working

  1. #1
    Join Date
    Jun 2011
    Posts
    2

    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:
    function runonclick()
    {
        var count = 0;
        var formlength = this.form.elements.length;
        while(count < formlength)
        {
            if(this.form.elements[count].tagName.toLowerCase() == "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());

  2. #2
    Join Date
    Dec 2010
    Posts
    207
    Event handlers are all lowercase, so the syntax should be:

    Code:
    buttonarray[count].onclick = runonclick;
    The .value property would be better assigned on load, so I would call
    runonclick on load and forget the other function.

    Why does it have to be <button> rather than <input type='button'> ?


    Q: I found this code...
    A: Then find its author.

  3. #3
    Join Date
    Jun 2011
    Posts
    2
    Quote Originally Posted by clueful View Post
    Event handlers are all lowercase, so the syntax should be:

    Code:
    buttonarray[count].onclick = runonclick;
    Thank you, did not know that was an issue.

    Quote Originally Posted by clueful View Post
    The .value property would be better assigned on load, so I would call
    runonclick on load and forget the other function.

    Why does it have to be <button> rather than <input type='button'> ?
    I do not follow, can you explain it ?

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles