changing the content of a table row in JavaScript

P

PJ6

I know this isn't exactly the correct forum to ask, but I've had such bad
luck looking everywhere else I thought I'd try here.

I want to update the content of a table row using JavaScript, but IE throws
exceptions when I try to change the innerHTML property, or use Prototype's
Replace function on it. For a change that only affects one row, I end up
having to rerender the entire table...

Any workaround?

Paul
 
B

bruce barker

you can change the innerHTML of <td>'s, but not <tr>'s. if you need to
change the <tr>, remove its child Nodes and re-add them thru the dom
node interface.

-- bruce (sqlwork.com)
 
L

Lit

PJ6,

It does not work for me either, Need to change only the td with span inside
here is an example that works

<html>

<head>

<title>Change Table Row in Table using JavaScript</title>

<script language="JavaScript" >
function ch()
{
document.getElementById("spanTD21").innerHTML = "x,1";
document.getElementById("spanTD22").innerHTML = "x,2";
document.getElementById("spanTD23").innerHTML = "x,3";

}
</script>

</head>

<body>

<table border="1" onClick="javascript:ch();" id="T1">
<tr id="R1">
<td>1,1</td>
<td>1,2</td>
<td>1,3</td>
</tr>

<tr id="R2">
<td><span id="spanTD21">2,1</span></td>
<td><span id="spanTD22">2,2</span></td>
<td><span id="spanTD23">2,3</span></td>
</tr>
<tr id="R3">
<td>3,1</td>
<td>3,2</td>
<td>3,3</td>
</tr>

</table>

</body>

</html>

Lit
 

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,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top