...

View Full Version : moveRow changes checkbox checked attribute



jschweickart
06-11-2004, 09:46 PM
I use a javascript utility to give my html tables nice features, such as column-header click-sorting, row-selection capability, etc. I, recently, noticed that when sorting, any checkbox checked attributes revert back to the values the page loaded with after I resorted the table. For example, if a checkbox in the table was unchecked when the page loaded, and then I checked it and resorted, my check would dissappear. The same effect happens if it loaded checked and I uncheck it. It appears "rechecked" after sorting. I have reduced this to a small test case that I have included. I have narrowed it down to the moveRow() method. I really don't want to capture all my checkbox values before sorting and reset them afterwards. Does anyone know of a good work-around for this?

Thanks,
Joe Schweickart

Small example of problem:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>
<head>
<title>Untitled</title>
</head>

<body>
check any checkbox and then click on column header. moveRow() will cause the check to "dissappear"
<table id="table1" border="1">
<tr>
<th onclick="moveTheRowsAround();">
header 1
</th>
<th onclick="moveTheRowsAround();">
header 2
</th>
</tr>
<tr>
<td>
cell(0,1)
</td>
<td>
<input type=checkbox name="checkbox2">
</td>
</tr>
<tr>
<td>
cell(1,1)
</td>
<td>
<input type=checkbox name="checkbox2">
</td>
</tr>
<tr>
<td>
cell(2,1)
</td>
<td>
<input type=checkbox name="checkbox3">
</td>
</tr>
</table>

<script language="javascript">
function moveTheRowsAround()
{
document.getElementById('table1').moveRow(1,3);
}
</script>

</body>
</html>

neofibril
06-12-2004, 02:41 AM
It appears that accounting for 'checked' is the only way.



<body>
<script language="javascript">
function moveTheRowsAround()
{
var el = tbod.all.tags("INPUT"), i = 0, arr = [];
for(; i < el.length; i++)
if(el[i].type == "checkbox")
arr.push(el[i], el[i].checked);
tbod.moveRow(0,2);
while(arr.length > 0)
arr.shift().checked = arr.shift();
}
</script>
<table border="1">
<thead>
<tr>
<th onclick="moveTheRowsAround();">
header 1
</th>
<th onclick="moveTheRowsAround();">
header 2
</th>
</thead>
<tbody id="tbod">
</tr>
<tr>
<td>
cell(0,1)
</td>
<td>
<input type=checkbox>
</td>
</tr>
<tr>
<td>
cell(1,1)
</td>
<td>
<input type=checkbox>
</td>
</tr>
<tr>
<td>
cell(2,1)
</td>
<td>
<input type=checkbox>
</td>
</tr>
</tbody>
</table>
</body>

jschweickart
06-14-2004, 01:46 PM
Thanks much. That's a much more elegant solution than I was contemplating. Also, since this appears to be an IE bug, is there an official place to report these to Microsoft? I looked on MSDN and didn't see anything that jumped out.

Joe

neofibril
06-15-2004, 12:46 AM
I'd guess that the Internet Explorer home page would have contact info.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum