SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    Always learning viveknarula's Avatar
    Join Date
    Mar 2006
    Location
    INDIA
    Posts
    418
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Exclamation innerHTML problem in IE

    hello friends.
    i am creating rows in a table with innerHTML property of a field. i have created a table with id "tb". and then i put it as document.getElementById("tb").innerHTML="<tr><td>field dynamic</td></tr>"; it is working well in firefox but IE is not working. i have googled for it i got the solution but some works in IE only, some in Firefox only.

    Can anyone give me the common solution for it which runs in both.

  2. #2
    SitePoint Enthusiast ada80ro's Avatar
    Join Date
    Apr 2005
    Posts
    64
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    In IE you cannot use innerHTML for creating table elements.

    For a solution see:
    http://msdn.microsoft.com/workshop/a.../innerhtml.asp
    and
    http://msdn.microsoft.com/workshop/a...uildtables.asp

    The solution also works in FF.

  3. #3
    SitePoint Wizard gRoberts's Avatar
    Join Date
    Oct 2004
    Location
    Birtley, UK
    Posts
    2,439
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i resolve this issue by sticking the table in a div, and using the innerHTML value to set the table.

    If you hadn't already looked at those links, you have to use dom to access the table directly.


  4. #4
    Always learning viveknarula's Avatar
    Join Date
    Mar 2006
    Location
    INDIA
    Posts
    418
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Unhappy

    Thanks robert for u r interest, if u can please show me some code that u have used inside div.

    Thanx

  5. #5
    SitePoint Wizard gRoberts's Avatar
    Join Date
    Oct 2004
    Location
    Birtley, UK
    Posts
    2,439
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    well, because the dawn of Ajax has arrived, and it's becoming more popular my colleague asked me to convert a website we have which is built using asp.net into an ajax version.

    Using an ajax component, I called a method on the server which populated my web control, then using some fancy scripting I told it to generate the HTML for that control and return it back to the javascript.

    Then I simply called

    Code:
    function PopulateTable(id, data)
    {
       var tbl = document.getElementById(id);
       if(tbl.nodeName == 'DIV')
    	 tbl.innerHTML = data;
       else
       {
    	  var parentDiv = tbl.parentNode;
    	  parentDiv.innerHTML = data;
       }
    }
    so if you have the following:

    Code:
    <html>
    <head>
    <title>test</title>
    </head>
    <body>
    <div id="test">
    <table id="test1">
     <tr><td>This is a test</td></tr>
     <tr><td>Does It Work?</td></tr>
    </table>
    </body>
    </html>
    if i were to call

    Code:
    PopulateTable('test','<table id="test1"><tr><td>Does this work></td></tr><tr><td>Yes it does!</td></tr></table>');
    it would simply insert the html code into the div, displaying the table.

    where as if you were to call

    Code:
     PopulateTable('test1','<table id="test1"><tr><td>Does this work></td></tr><tr><td>Yes it does!</td></tr></table>');
    it would simply get the parentNode which will be the div and populate it with the data.

    Gav


  6. #6
    SitePoint Member
    Join Date
    Jul 2006
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think you're better off walking the DOM and using createElement and createTextNode to do what you want. Sorry I don't have a code example, but there should be plenty on the web.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •