Changing innerHTML for div

Discussion in 'JavaScript and AJAX' started by rekha, Jan 12, 2010.

  1. rekha

    rekha New Member

    Joined:
    Jan 17, 2008
    Messages:
    83
    Likes Received:
    0
    Trophy Points:
    0
    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.
     
  2. SaswatPadhi

    SaswatPadhi ~ Б0ЯИ Τ0 С0δЭ ~

    Joined:
    May 5, 2009
    Messages:
    1,342
    Likes Received:
    55
    Trophy Points:
    0
    Occupation:
    STUDENT !
    Location:
    Orissa, INDIA
    Home Page:
    http://www.crackingforfun.blogspot.com
    I think you missed a pair of quotes here :
    Code:
    .
    .
    	else
    	{
    [COLOR="Red"]	    tbl.innerHTML="<img src=../../temp/"+name1+".png>";[/COLOR]
    		tbl.style.display = 'block';
     	
    	}
    .
    .
    
    Try changing it to : tbl.innerHTML="<img src=\"../../temp/"+name1+".png\">";
     
  3. rekha

    rekha New Member

    Joined:
    Jan 17, 2008
    Messages:
    83
    Likes Received:
    0
    Trophy Points:
    0
    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........
     
  4. venami

    venami New Member

    Joined:
    Dec 26, 2008
    Messages:
    195
    Likes Received:
    10
    Trophy Points:
    0
    Occupation:
    Software Professional
    Location:
    India, Tamil Nadu, Cuddalore
    Home Page:
    http://mvenkatapathy.wordpress.com
    Is the permission for the image file set correctly?
     
  5. venami

    venami New Member

    Joined:
    Dec 26, 2008
    Messages:
    195
    Likes Received:
    10
    Trophy Points:
    0
    Occupation:
    Software Professional
    Location:
    India, Tamil Nadu, Cuddalore
    Home Page:
    http://mvenkatapathy.wordpress.com
    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("[COLOR="Red"]chart[/COLOR]");
        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=# [COLOR="Red"]onclick="toggleVisiblity()"><img src="../images/chart.gif"[/COLOR] border=0></a>
    </div>
    <div id='chart' style='display:none;' align=center>
    </div>
    </body>
    
    </html>
    
    Let me know whether this works or not.
     
    Last edited: Jan 13, 2010
  6. rekha

    rekha New Member

    Joined:
    Jan 17, 2008
    Messages:
    83
    Likes Received:
    0
    Trophy Points:
    0
    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.
     
    Last edited: Jan 13, 2010
  7. venami

    venami New Member

    Joined:
    Dec 26, 2008
    Messages:
    195
    Likes Received:
    10
    Trophy Points:
    0
    Occupation:
    Software Professional
    Location:
    India, Tamil Nadu, Cuddalore
    Home Page:
    http://mvenkatapathy.wordpress.com
    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.
     
  8. rekha

    rekha New Member

    Joined:
    Jan 17, 2008
    Messages:
    83
    Likes Received:
    0
    Trophy Points:
    0
    Hi venami,

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

    urstop New Member

    Joined:
    Oct 17, 2007
    Messages:
    84
    Likes Received:
    0
    Trophy Points:
    0
    Also, are your sure that it is going into the IF block of your javascript, did you verify that.
     
  10. rekha

    rekha New Member

    Joined:
    Jan 17, 2008
    Messages:
    83
    Likes Received:
    0
    Trophy Points:
    0
    Hi,

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

    rekha New Member

    Joined:
    Jan 17, 2008
    Messages:
    83
    Likes Received:
    0
    Trophy Points:
    0
    Pls someone help me to solve this issue.
     
  12. rekha

    rekha New Member

    Joined:
    Jan 17, 2008
    Messages:
    83
    Likes Received:
    0
    Trophy Points:
    0
    Hi,

    Still I haven't solve the issue.Pls anyone here help me.Why it is not working in IE.:worried:
     
  13. rekha

    rekha New Member

    Joined:
    Jan 17, 2008
    Messages:
    83
    Likes Received:
    0
    Trophy Points:
    0
    Hi,

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

    ManzZup New Member

    Joined:
    May 9, 2009
    Messages:
    278
    Likes Received:
    43
    Trophy Points:
    0
    Occupation:
    Production Manager:Software @ ZONTEK
    Location:
    Sri Lanka
    Home Page:
    http://zontek.zzl.org
    tbl.innerHTML="<img src=../../temp/"+name1+".png />";

    DONT FORGET that the img closes like that
     
  15. rekha

    rekha New Member

    Joined:
    Jan 17, 2008
    Messages:
    83
    Likes Received:
    0
    Trophy Points:
    0
    Hi,

    I have solved the issue.In IE the image is displayed from the cache.So I have changed the img src to the image file with current date and time and the issue solved.

    Thanks for all ur help.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice