...

View Full Version : getelement problems



Anishgiri
08-24-2010, 07:37 AM
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.





<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>





<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>

Old Pedant
08-24-2010, 07:24 PM
Sorry, but I don't believe you.

There is no way in the world that this code worked in *ANY* browser:

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

alert( peter.length );

but certainly not x.length

Old Pedant
08-24-2010, 07:30 PM
And the first example, changing the header, worked fine for me with MSIE 8.

Anishgiri
08-25-2010, 01:26 AM
Sorry, I am trying to modify the first code and I forgot to post the original lines. Yeah it shoudl be
alert(peter.length);

Sorry but what should I put with the header for this two codes to work on IE8?

low tech
08-25-2010, 02:00 AM
Hi

With the change made (x to peter)

Both codes work in IE8 for me.

Old Pedant
08-25-2010, 02:01 AM
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.

Anishgiri
08-25-2010, 03:23 AM
Weird, the two codes does not work on my ie8, my active scripting on ie 8 is enable, maybe may ie 8 is corrupated.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum