By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,587 Members | 634 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,587 IT Pros & Developers. It's quick & easy.

innertext - unknown runtime error

P: n/a
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>

Nov 23 '05 #1
Share this Question
Share on Google+
8 Replies


P: n/a
su***************@gmail.com said the following on 11/21/2005 2:50 AM:
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


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/
Nov 23 '05 #2

P: n/a
su***************@gmail.com wrote:
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


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
Nov 23 '05 #3

P: n/a


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>

Nov 23 '05 #4

P: n/a
VK
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>

Nov 23 '05 #5

P: n/a
su***************@gmail.com wrote:

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.
A tbody element is mandatory even though the tags are optional.
Browsers will add a tbody element where it is needed.

so i try with createElement

<script language=javascript>
The language attribute is deprecated, type is required:

<script type="text/javascript">

function test()
{
alert(document.getElementById('tbl1').innerHTML);
document.getElementById('tbl1').innerHTML+='<tr><t d>EFG</td></tr>';
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);

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

--
Rob
Nov 23 '05 #6

P: n/a
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';

Nov 23 '05 #7

P: n/a
i got the soln, ie className

Nov 23 '05 #8

P: n/a
su***************@gmail.com wrote:
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';

^^^^^^^^^
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
Nov 23 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.