Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

getElementID and innerHTML throwing an error 1

Status
Not open for further replies.

ahmun

IS-IT--Management
Jan 7, 2002
432
US
Hi all..

can someone look at the following test code and explain why I get the error:

Line: 9
Char: 2
Error: Object doesn't support this property or method
Code: 0
.
.
Code:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
<script language="javascript" type="text/javascript">
<!--
function setText(frmObject)
{
	document.getElementByID("displayTextDiv").innerHTML=frmObject.value+" - size";[red]line 9[/red]
}
// -->
</script>
</head>

<body>
<form name="form1" method="post" action="">
  <select name="lstItems" id="lstItems" onChange="setText(this);">
    <option value="S" selected>Small</option>
    <option value="M">Medium</option>
    <option value="L">Large</option>
  </select>
</form>
<div id="displayTextDiv">Content for id "displayTextDiv" Goes Here</div>
</body>
</html>

line 9 is the javsacript code


Earnie Eng
 
This was puzzling, I really had to stare at it for awhile.

Turns out, it was a small capitilization error.
make the D in ID lowercase in this line:
Code:
document.getElementByI[COLOR=red][b]d[/b][/color]("displayTextDiv").innerHTML=frmObject.value+" - size";line 9

hope that helps

"The longer I live the more I see that I am never wrong about anything, and that all the pains that I have so humbly taken to verify my notions have only wasted my time." -George Bernard Shaw
 
huh... stoopid on my part!

I guess all that VBscripting has gotten me lazy...

Thanks elegidito! it Worked!

can you or anyone also help me with some differences?

getElementByID vs. getElementByTagName
innerHTML vs. innerText

Which one is better? Which one is more cross-platform?

Earnie Eng
 
good eye, by the way... a star for you!

Earnie Eng
 
Since they all serve different purposes, im not sure one can be said to be better than the other.

getElementById can be used for more singular purposes, whereas getElementsByTagName can be used to grab all objects in a document with a certain tag name.

In the case of innerHTML and innerText, they both can be used to change the text inside an object. However, innerHTML supports the use of HTML tags. InnerText will simply print the tags as plain text.

As far as compatibility is concerned, I'm pretty sure all four of those properties are supported by IE 5+ and Mozilla.

Hope that helps

"The longer I live the more I see that I am never wrong about anything, and that all the pains that I have so humbly taken to verify my notions have only wasted my time." -George Bernard Shaw
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top