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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

innerHTML won't display

Status
Not open for further replies.

TheDust

Programmer
Aug 12, 2002
217
0
0
US
This is quite strange... I can't get innerHTML to write almost anywhere on the page. I must be doing SOMETHING wrong and maybe someone can help me see something I didn't realize was required...

Code:
<html>
<head>
<title></title>
<script language=&quot;JavaScript&quot;>
	document.all.portfolio.innerHTML = &quot;hooray&quot;;
</script>
</head>
<body>
<div id=&quot;mainframe&quot;>
	<div id=&quot;banner&quot;></div>
	<div id=&quot;leftframe&quot;>
		<div id=&quot;flower1&quot;></div>
		<div id=&quot;flower2&quot;></div>
		Left
	</div>
	<div id=&quot;rightframe&quot;>
		<div id=&quot;portfolio&quot;></div>
	</div>
</div>
</body>
</html>

This does not work, and I have no idea why. Any ideas on this??
 
does this work?
document.getElementById(&quot;portfolio&quot;).innerHTML = &quot;hooray&quot;;

Known is handfull, Unknown is worldfull
 
The point is that you have called the script before the element has even loaded on the page! So do it in a function which can be called onevent(like onload):
<script language=&quot;JavaScript&quot;>
function change() {
document.all.portfolio.innerHTML = &quot;hooray&quot;;
}
</script>
</head>
<body onload=&quot;change()&quot;>
 
Thanks... placing it in a function worked... I just have one more problem... the HTML I'm trying to write into the DIV tag is to place a SWF file in there. I'm using the following code:

<code>
<head>
<script language=&quot;JavaScript&quot;>
var colorScheme;
var flashMarkup;
colorScheme = &quot;red&quot;;
function loadPortfolio(color) {
flashMarkup += &quot;<!-- URL's used in the movie--><a href\&quot;= text used in the movie-->&quot;;
flashMarkup += &quot;<object classid=\&quot;clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\&quot; codebase=\&quot; width=\&quot;175\&quot; height=\&quot;145\&quot; id=\&quot;images/portfolio_&quot; + color + &quot;\&quot;>&quot;;
flashMarkup += &quot;<param name=\&quot;movie\&quot; value=\&quot;images/portfolio_&quot; + color + &quot;.swf\&quot; /><param name=\&quot;quality\&quot; value=\&quot;high\&quot; />&quot;;
flashMarkup += &quot;<embed src=\&quot;images/portfolio_&quot; + color + &quot;.swf\&quot; quality=\&quot;high\&quot; width=\&quot;175\&quot; height=\&quot;145\&quot; name=\&quot;portfolio_&quot; + color + &quot;\&quot; type=\&quot;application/x-shockwave-flash\&quot; pluginspace=\&quot; flashMarkup += &quot;</object>&quot;;
document.all.portfolio.innerHTML = flashMarkup;
}
</script>
</head>

<body onLoad=&quot;loadPortfolio()&quot;>
</code>

The Flash displays just fine, but for some reason, no matter what I take out of the code, it also prints &quot;undefined&quot; on the screen just above the SWF file. Does anyone know what is causing this?
 
Never mind, I figured that out... I just had to define flashMarkup with = &quot;&quot; to create an empty string type variable.

Thanks for your help, everyone!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top