Go4Expert

Go4Expert (http://www.go4expert.com/)
-   JavaScript and AJAX (http://www.go4expert.com/forums/javascript/)
-   -   Changing innerHTML for div (http://www.go4expert.com/forums/changing-innerhtml-div-t20648/)

rekha 12Jan2010 19:02

Changing innerHTML for div
 
Hi,

Div innerHTMl not working in IE6.

Code:

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

    if(tbl!=null){
        if (tbl.style.display == 'block')
        {
            tbl.innerHTML="";
                tbl.style.display = 'none';
               
        }
        else
        {
            tbl.innerHTML="<img src=../../temp/"+name1+".png>";
                tbl.style.display = 'block';
       
        }
        }
}

Code:

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

SaswatPadhi 12Jan2010 19:41

Re: Changing innerHTML for div
 
I think you missed a pair of quotes here :
Code:

.
.
        else
        {
            tbl.innerHTML="<img src=../../temp/"+name1+".png>";
                tbl.style.display = 'block';
       
        }
.
.

Try changing it to : tbl.innerHTML="<img src=\"../../temp/"+name1+".png\">";

rekha 13Jan2010 10:14

Re: Changing innerHTML for div
 
Hi

Thanks for you reply.But I tried that also but is is also not working.The issue is not with the quotes.I think the issue is in the updation of the image.The new image is updated in the temp folder.But it is not updated even when the page is refreshed.

Pls help........

venami 13Jan2010 11:21

Re: Changing innerHTML for div
 
Is the permission for the image file set correctly?

venami 13Jan2010 11:50

Re: Changing innerHTML for div
 
I have made little changes to your code and posted here the corrected one. The problem seems to be the '\' escape character that you used, which is not required in your case. The changes are marked with red colour.

Code:

<html>

<head>
<title>Sample Page</title>
<script type="text/javascript">
function toggleVisiblity()
{
  var name1="eg";
 
    var tbl = document.getElementById("chart");
    alert(tbl);
    alert(tbl.style.display);
    alert(tbl.nodeName);
    var clink=document.getElementById("chartlink");

    if(tbl!=null){
    if (tbl.style.display == 'block')
    {
        tbl.innerHTML="";
        tbl.style.display = 'none';
       
    }
    else
    {
        tbl.innerHTML="<img src=../images/" + name1 + ".png>";
        tbl.style.display = 'block';
   
    }
    }
}
</script>
</head>

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

</html>

Let me know whether this works or not.

rekha 13Jan2010 12:07

Re: Changing innerHTML for div
 
Hi venami,

I used the code inside php.So I used the escape symbol.Here I quoted just the code.

And also the permission for the image is set right.It is working fine in firefox.In IE it is not working.

venami 13Jan2010 12:13

Re: Changing innerHTML for div
 
Then it might be the Javascript compatibility issue with IE.

Since I wont be having access to the web server till Sunday, I could not help you immediately. :) Otherwise I could have done something now.

rekha 13Jan2010 12:34

Re: Changing innerHTML for div
 
Hi venami,

Its ok.Thanks for your replies.If I found the workaround I will put it here.

urstop 13Jan2010 15:06

Re: Changing innerHTML for div
 
Also, are your sure that it is going into the IF block of your javascript, did you verify that.

rekha 13Jan2010 15:35

Re: Changing innerHTML for div
 
Hi,

Yes.It is going to the if block and tbl is not null only.


All times are GMT +5.5. The time now is 14:58.