Changing innerHTML for div


Div innerHTMl not working in IE6.

function toggleVisiblity()
  var name1="eg";
	var tbl = document.getElementById("chart1");alert(tbl);alert(;
alert(tbl.nodeName);	var clink=document.getElementById("chartlink");

	if ( == 'block')
	    tbl.innerHTML=""; = 'none';
	    tbl.innerHTML="<img src=../../temp/"+name1+".png>"; = 'block';
<div align=left><a id='chartlink' href=# onclick=\\"toggleVisiblity()\\"><img src=\\"../images/chart.gif\\" border=0></a></div><div id='chart' style='display:none;' align=center></div>

In this code everytime eg.png is a new image.But the new image is not shown in the div but it is updating in the temp folder.

Two things I notice right away. The script is looking for “chart1” but the id is “chart”.

And if the variable “tbl” is not null it does stuff with it, but if it is null it tries to do something else. Yet if it’s null how can it use it?


Thanks for your reply.Sorry I wrongly entered ad chart in the code here.But my actual code contains chart1 only.

And also if tbl is null means no chart is created and there is nothing to display.So I used the condition to execute the code only if tbl is not null.

I just noticed the quotation marks around the function call in the HTML are escaped. Does it work like

<a id='chartlink' href=# onclick="toggleVisiblity();">
		<img src="../images/chart.gif" border=0>

BTW, it should be easier if you adopt some consistency. You have attribute values inside single quotes, double quotes, and no quotes (which is invalid).

<a id="chartlink" href="#" onclick="toggleVisiblity();">
		<img src="../images/chart.gif" border="0">

*notice the difference in the color highlighting.

Now does your code work in firefox? I wrote a 2 option menu the second one appearing after an option was selected from the first using the innerHTML. It works great in firefox. Does not work in IE… Hope you find a solution!

It is working fine in firefox.But in IE it is not working.Someone help me to solve this issue.


I found where is the issue.If I clear cache data in Internet Explorer and run the code,it is working fine.IE displays the image from the cache data instead of displaying from the temp folder where the image is stored.But I don’t know how to solve this.I want the image to be displayed from the temp folder in my server.

Anyone who knows can suggest me a good solution.