innertext - unknown runtime error

S

sudhaoncyberworld

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><td>EFG</td></tr>';
}
</script>
<body>
<table id='tbl1'>
<tbody id='tbd1'>
<tr>
<td onmouseover=test() >
ABC
</td>
</tr>
</tbody>
</table>
</body>
</html>
 
R

Randy Webb

(e-mail address removed) 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.
 
R

RobG

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.
 
S

sudhaoncyberworld

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><td>EFG</td></tr>';

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

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>
 
R

RobG

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:

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

sudhaoncyberworld

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';
 
T

Thomas 'PointedEars' Lahn

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top