Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Feb 2004
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    moveRow changes checkbox checked attribute

    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>

  • #2
    Regular Coder
    Join Date
    Jun 2004
    Location
    underground
    Posts
    186
    Thanks
    0
    Thanked 0 Times in 0 Posts
    It appears that accounting for 'checked' is the only way.

    Code:
    <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>

  • #3
    New to the CF scene
    Join Date
    Feb 2004
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #4
    Regular Coder
    Join Date
    Jun 2004
    Location
    underground
    Posts
    186
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I'd guess that the Internet Explorer home page would have contact info.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •