Connecting Tech Pros Worldwide Help | Site Map
 
 
LinkBack Thread Tools Search this Thread
  #1  
Old November 23rd, 2005, 03:32 AM
sudhaoncyberworld@gmail.com
Guest
 
Posts: n/a
Default 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>Untitled Page</title>
</head>
<script language=javascript>
function test()
{
alert(document.getElementById('tbd1').innerHTML);
document.getElementById('tbd1').innerHTML+='<tr><t d>EFG</td></tr>';
}
</script>
<body>
<table id='tbl1'>
<tbody id='tbd1'>
<tr>
<td onmouseover=test() >
ABC
</td>
</tr>
</tbody>
</table>
</body>
</html>

  #2  
Old November 23rd, 2005, 03:32 AM
Randy Webb
Guest
 
Posts: n/a
Default Re: innertext - unknown runtime error

sudhaoncyberworld@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.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
  #3  
Old November 23rd, 2005, 03:32 AM
RobG
Guest
 
Posts: n/a
Default Re: innertext - unknown runtime error

sudhaoncyberworld@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
  #4  
Old November 23rd, 2005, 03:32 AM
sudhaoncyberworld@gmail.com
Guest
 
Posts: n/a
Default 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=javascript>
function test()
{
alert(document.getElementById('tbl1').innerHTML);
document.getElementById('tbl1').innerHTML+='<tr><t d>EFG</td></tr>';

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

  #5  
Old November 23rd, 2005, 03:32 AM
VK
Guest
 
Posts: n/a
Default 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>

  #6  
Old November 23rd, 2005, 03:32 AM
RobG
Guest
 
Posts: n/a
Default Re: innertext - unknown runtime error

sudhaoncyberworld@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=javascript>[/color]

The language attribute is deprecated, type is required:

<script type="text/javascript">

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

Replace the above line with:

if (!document.getElementById || !document.createElement) return;
var row = document.getElementById('tbl1').insertRow(-1);
var cell = document.createElement('td');
cell.appendChild(document.createTextNode('EFG'));
row.appendChild(cell);
[color=blue]
>
> }
> </script>
> <body>
> <table id='tbl1'>
> <tr>
> <td onmouseover=test() >
> ABC
> </td>
> </tr>
> </table>
> </body>
> </html>
>[/color]


--
Rob
  #7  
Old November 23rd, 2005, 07:05 AM
sudhaoncyberworld@gmail.com
Guest
 
Posts: n/a
Default 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.createElement('LABEL');
lbl.innerText='ABC';
lbl.id='lblid';
lbl.class='bold11';

  #8  
Old November 23rd, 2005, 07:25 AM
sudhaoncyberworld@gmail.com
Guest
 
Posts: n/a
Default Re: innertext - unknown runtime error

i got the soln, ie className

  #9  
Old November 23rd, 2005, 02:45 PM
Thomas 'PointedEars' Lahn
Guest
 
Posts: n/a
Default Re: innertext - unknown runtime error

sudhaoncyberworld@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.createElement('LABEL');
> 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.createTextNode('ABC');
lbl.appendChild(txt);

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


PointedEars
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 205,248 network members.