Forum Moderators: open

Message Too Old, No Replies

OnMouseover, change content of table

         

yllai

2:51 am on Feb 15, 2006 (gmt 0)

10+ Year Member



Hi,

I have a table with 1 row 2 columns. In row 1 column 1, I have an image. By default, row 1 column 2 is blank. So, what I want to do is, when i move my mouse to the image at row 1 column 1, then will have a table to be shown in row 1 column two. I tried to do this with getElementId function, but it does not work. Any idea? any example or tutorial for doing this?

Thanks.

Rambo Tribble

3:00 am on Feb 15, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If you are trying to do this on IE, make sure the target table cells are within a tbody. IE is flaky at producing changes to a table without a tbody (among oh, so many other flakinesses).

prasanth jvrs

12:46 pm on Feb 15, 2006 (gmt 0)

10+ Year Member



Hi,

Below code can help you.

<html>
<body>
<p>Click on the table header to sort in ascending order.</p>
<table border="1" id="tblSort">
<thead>
<tr>
<th>Last Name</th>
</tr>
</thead>
<tbody>
<tr>
<td onmouseout="loaddummy()" onmouseover="loadtable()"><img src="1.jpg"></td><td></td>
</tr>
<tr>
<td>Johnson</td><td>Pradeep</td>
</tr>
<tr>
<td>Henderson</td><td>Praveen</td>
</tr>
<tr>
<td>Williams</td><td>Syamala</td>
</tr>
<tr>
<td>Gilliam</td><td>Rama Krishna</td>
</tr>
<tr>
<td>Walker</td><td>Polepeddi Rama Lakshmi</td>
</tr>
</tbody>
</table>
</body>
</html>

<script>

function loaddummy() {
}

function loadtable() {
var oTBody = document.getElementById("tblSort").getElementsByTagName("tbody")[0];
var colDataRows = oTBody.rows;

//alert(colDataRows[0].cells[1]);

colDataRows[0].removeChild(colDataRows[0].cells[1]);

var cell41 = document.createElement("td");
cell41.setAttribute("innerHTML","<table border=1><tr><td>Governorpet</td><td>Vijayawada</td></tr><tr><td>Governorpet</td><td>Vijayawada</td></tr><tr><td>Governorpet</td><td>Vijayawada</td></tr></table>");

colDataRows[0].appendChild(cell41);

}
</script>

Thanks
Prasanth J.V.R.S

Rambo Tribble

3:47 pm on Feb 15, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



At first glance, I suspect your problems stem from removing a table cell when, I think, all you want to do is change its content. At any rate, removing a single td violates the table's integrity.