innertext - unknown runtime error

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • sudhaoncyberworld@gmail.com

    #1

    innertext - unknown runtime error

    like below approach i need to add bulk of data in innertext, but for
    this simple case itself it is giving error, i badly need this approch
    and i failed with search also , so pl give me a soln asap, thanx in
    advance for spending ur time for me

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
    "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head>
    <title>Untitl ed Page</title>
    </head>
    <script language=javasc ript>
    function test()
    {
    alert(document. getElementById( 'tbd1').innerHT ML);
    document.getEle mentById('tbd1' ).innerHTML+='< tr><td>EFG</td></tr>';
    }
    </script>
    <body>
    <table id='tbl1'>
    <tbody id='tbd1'>
    <tr>
    <td onmouseover=tes t() >
    ABC
    </td>
    </tr>
    </tbody>
    </table>
    </body>
    </html>

  • Randy Webb

    #2
    Re: innertext - unknown runtime error

    sudhaoncyberwor ld@gmail.com said the following on 11/21/2005 2:50 AM:[color=blue]
    > like below approach i need to add bulk of data in innertext, but for
    > this simple case itself it is giving error, i badly need this approch
    > and i failed with search also , so pl give me a soln asap, thanx in
    > advance for spending ur time for me[/color]

    There is no use of innerText in your page. I assume you are referring to
    innerHTML instead since that is what you are using. IE doesn't like you
    attempting to change the innerHTML of a tbody. Either change the table's
    innerHTML or use DOM2 methods to create new elements and then append
    them to the table.

    It doesn't throw an error in Firefox but it doesn't do what you intended
    either.

    --
    Randy
    comp.lang.javas cript FAQ - http://jibbering.com/faq & newsgroup weekly
    Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/

    Comment

    • RobG

      #3
      Re: innertext - unknown runtime error

      sudhaoncyberwor ld@gmail.com wrote:[color=blue]
      > like below approach i need to add bulk of data in innertext, but for
      > this simple case itself it is giving error, i badly need this approch
      > and i failed with search also , so pl give me a soln asap, thanx in
      > advance for spending ur time for me[/color]

      What Randy said, plus Microsoft say in their documentation don't use
      innerHTML to modify tbody, tr, th or td elements, use DOM (they actually
      refer to a 'table object model', but DOM is a better bet).

      If you are going to use innerHTML near a table, write the entire table
      or just cell content, no in between.


      --
      Rob

      Comment

      • sudhaoncyberworld@gmail.com

        #4
        Re: innertext - unknown runtime error



        Thanks for ur replies, Sorry, in my subject i wrongly mentioned as
        innertext instead of InnerHTML and i tried with table also, that also
        throwing the same error (i am using IE 6) and eventhough i did not add
        the tbody it is automatically adding table body, ie. y i added myself.
        so i try with createElement

        <script language=javasc ript>
        function test()
        {
        alert(document. getElementById( 'tbl1').innerHT ML);
        document.getEle mentById('tbl1' ).innerHTML+='< tr><td>EFG</td></tr>';

        }
        </script>
        <body>
        <table id='tbl1'>
        <tr>
        <td onmouseover=tes t() >
        ABC
        </td>
        </tr>
        </table>
        </body>
        </html>

        Comment

        • VK

          #5
          Re: innertext - unknown runtime error

          You cannot manipulate table structure over innerHTML.

          Overall you are very rarely able to manipulate document DOM using
          innerHTML.

          This method is cross-browser reliable only for sample things like
          setting rich-formatted HTML content to an existing element (like table
          cell, div, span etc.)

          In your case you have to use the table manipulation mechanics by W3C or
          by IE-exclusive way. Description and comparison of both please see
          here:

          <http://msdn.microsoft. com/workshop/author/tables/buildtables.asp >

          Comment

          • RobG

            #6
            Re: innertext - unknown runtime error

            sudhaoncyberwor ld@gmail.com wrote:[color=blue]
            >
            > Thanks for ur replies, Sorry, in my subject i wrongly mentioned as
            > innertext instead of InnerHTML and i tried with table also, that also
            > throwing the same error (i am using IE 6) and eventhough i did not add
            > the tbody it is automatically adding table body, ie. y i added myself.[/color]

            A tbody element is mandatory even though the tags are optional.
            Browsers will add a tbody element where it is needed.

            [color=blue]
            > so i try with createElement
            >
            > <script language=javasc ript>[/color]

            The language attribute is deprecated, type is required:

            <script type="text/javascript">

            [color=blue]
            > function test()
            > {
            > alert(document. getElementById( 'tbl1').innerHT ML);
            > document.getEle mentById('tbl1' ).innerHTML+='< tr><td>EFG</td></tr>';[/color]

            Replace the above line with:

            if (!document.getE lementById || !document.creat eElement) return;
            var row = document.getEle mentById('tbl1' ).insertRow(-1);
            var cell = document.create Element('td');
            cell.appendChil d(document.crea teTextNode('EFG '));
            row.appendChild (cell);
            [color=blue]
            >
            > }
            > </script>
            > <body>
            > <table id='tbl1'>
            > <tr>
            > <td onmouseover=tes t() >
            > ABC
            > </td>
            > </tr>
            > </table>
            > </body>
            > </html>
            >[/color]


            --
            Rob

            Comment

            • sudhaoncyberworld@gmail.com

              #7
              Re: innertext - unknown runtime error

              Hi all

              In above style i created the element, if i try to assign css class for
              that it is bugging , y

              lbl=document.cr eateElement('LA BEL');
              lbl.innerText=' ABC';
              lbl.id='lblid';
              lbl.class='bold 11';

              Comment

              • sudhaoncyberworld@gmail.com

                #8
                Re: innertext - unknown runtime error

                i got the soln, ie className

                Comment

                • Thomas 'PointedEars' Lahn

                  #9
                  Re: innertext - unknown runtime error

                  sudhaoncyberwor ld@gmail.com wrote:
                  [color=blue]
                  > In above style i created the element, if i try to assign css class for
                  > that it is bugging , y
                  >
                  > lbl=document.cr eateElement('LA BEL');
                  > lbl.innerText=' ABC';[/color]
                  ^^^^^^^^^
                  This is IE only. You are mixing features of different DOMs (above:
                  W3C DOM; here: IE DOM) without feature test which is a Bad Thing.
                  You should write instead _at least_

                  var txt = document.create TextNode('ABC') ;
                  lbl.appendChild (txt);

                  <URL:http://www.pointedears .de/scripts/test/whatami>


                  PointedEars

                  Comment

                  Working...