Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    Regular Coder
    Join Date
    May 2010
    Posts
    219
    Thanks
    0
    Thanked 0 Times in 0 Posts

    getelement problems

    This code came from http://www.w3schools.com. I tested it on ff, opera and google chrome they worked. But on IE8 it did not work. Is there a solution for this? I search google but I need not find any clear answers. My active scripting on ie 8 is enable.


    Code:
    <html>
    <body>
    
    <h1 id="header">Old Header</h1>
    
    <script type="text/javascript">
    document.getElementById("header").innerHTML="New Header";
    </script>
    
    <p>"Old Header" was changed to "New Header"</p>
    
    </body>
    </html>
    Code:
    <html>
    <head>
    <script type="text/javascript">
    function getElements()
      {
      var peter=document.getElementsByTagName("input");
      alert(x.length);
      }
    </script>
    </head>
    <body>
    
    <input type="text" size="20" /><br />
    <input type="text" size="20" /><br />
    <input type="text" size="20" /><br /><br />
    <input type="button" onclick="getElements()" value="How many input elements?" />
    
    </body>
    </html>

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    26,561
    Thanks
    80
    Thanked 4,495 Times in 4,459 Posts
    Sorry, but I don't believe you.

    There is no way in the world that this code worked in *ANY* browser:
    Code:
    function getElements()
      {
      var peter=document.getElementsByTagName("input");
      alert(x.length);
      }
    You do not have a variable named x, so there is no possible way you can get the .length property of x. You could do
    Code:
        alert( peter.length );
    but certainly not x.length
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #3
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    26,561
    Thanks
    80
    Thanked 4,495 Times in 4,459 Posts
    And the first example, changing the header, worked fine for me with MSIE 8.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #4
    Regular Coder
    Join Date
    May 2010
    Posts
    219
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Sorry, I am trying to modify the first code and I forgot to post the original lines. Yeah it shoudl be
    Code:
    alert(peter.length);
    Sorry but what should I put with the header for this two codes to work on IE8?

  • #5
    Regular Coder low tech's Avatar
    Join Date
    Dec 2009
    Posts
    852
    Thanks
    173
    Thanked 94 Times in 94 Posts
    Hi

    With the change made (x to peter)

    Both codes work in IE8 for me.
    Last edited by low tech; 08-25-2010 at 02:04 AM.

  • #6
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    26,561
    Thanks
    80
    Thanked 4,495 Times in 4,459 Posts
    As I said, the first code worked fine in IE8.

    And now the second code works fine, as well. (It correctly says 4.)

    And, yes, that is using MSIE 8. So I don't know what you think is wrong.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #7
    Regular Coder
    Join Date
    May 2010
    Posts
    219
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Weird, the two codes does not work on my ie8, my active scripting on ie 8 is enable, maybe may ie 8 is corrupated.


  •  

    Posting Permissions

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