Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7177863
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T16:48:10+00:00 2026-05-28T16:48:10+00:00

I’ve been struggling with this issue for a while now. Maybe you can help.

  • 0

I’ve been struggling with this issue for a while now. Maybe you can help.

I have a table with a checkbox at the beginning of each row. I defined a function which reloads the table at regular intervals. It uses jQuery’s load() function on a JSP which generates the new table.

The problem is that I need to preserve the checkbox values until the user makes up his mind on which items to select. Currently, their values are lost between updates.

The current code I use that tries to fix it is:

 refreshId = setInterval(function()
 {
        var allTicks = new Array();
        $('#myTable input:checked').each(function() {
            allTicks.push($(this).attr('id'));
        });
        $('#myTable').load('/get-table.jsp', null,
                function (responseText,textStatus, req ){
            $('#my-table').tablesorter();
            //alert(allTicks + ' length ' + allTicks.length);
            for (i = 0 ; i < allTicks.length; i++ )
                $("#my-table input#" + allTicks[i]).attr('checked', true);

        });
}, $refreshInterval); 

The id of each checkbox is the same as the table entry next to it.

My idea was to store all the checked checkboxes’ ids into an array before the update and to change their values after the update is done, as most of the entries will be preserved, and the ones that are new won’t really matter.

‘#myTable’ is the div in which the table is loaded and ‘#my-table’ is the id of the table which is generated. The checkbox inputs are generated along with the new table and with the same ids as before.

The weird thing is that applying tablesorter to the newly generated table works, but getting the elements with the stored ids doesn’t.

Any solutions?

P.S: I know that this approach to table generation isn’t really the best, but my JS skills were limited back then. I’d like to keep this solution for now and fix the problem.

EDIT:

Applied the syntax suggested by Didier G. and added some extra test blocks that check the status before and after the checkbox ticking.

Looks like this now:

refreshId = setInterval(function()
    {
        var allTicks = []
        var $myTable = $('#my-table');
        allTicks = $myTable.find('input:checked').map(function() { return this.id; });

        $('#myTable').load('/get-table.jsp', null,
        function (responseText,textStatus, req ){
            $myTable = $('#my-table');
            $('#my-table').tablesorter();
            var msg = 'Before: \n';
            $myTable.find('input').each(function(){
                msg = msg + this.id + " " + $(this).prop('checked') + '\n';
            });
            //alert(msg);
            //alert(allTicks + ' length ' + allTicks.length);
            for (i = 0 ; i < allTicks.length; i++ ){
                 $myTable.find('#' + allTicks[i]).prop('checked', true);
            }
            msg = 'After: '
            $myTable.find('input').each(function(){
                msg = msg + this.id + " " + $(this).prop('checked') + '\n';
            });
            //alert(msg);
        });
    }, $refreshInterval);

If I uncomment the alert lines, and check 2 checkboxes, on the next update I get (for 3 row table):

Before: host2 false
host3 false
host4 false

object [Object] length 2

After: host2 false
host3 false
host4 false

Also did a previous check on the contents of the array and it has all the correct entries.

Can the DOM change or working with an entirely new table instance be a cause of this?

EDIT2:

Here’s a sample of the table generated by the JSP (edited for confidentiality purposes):

<table id="my-table" class="tablesorter">
<thead>
    <tr>
        <th>Full Name</th> 
        <th>IP Address</th> 
        <th>Role</th> 
        <th>Job Slots</th> 
        <th>Status</th>
        <th>Management</th>
    </tr>
</thead>
<tbody>
    <tr>
        <td>head</td>
        <td>10.20.1.14</td>
        <td>H</td>
        <td>4</td>
        <td>ON</td>
        <td>Permanent</td>
    </tr>
    <tr>
        <td>
            <input type="checkbox" id="host2" name="host2"/>
            host2
        </td>
        <td>10.20.1.7</td>
        <td>C</td>
        <td>4</td>
        <td>BSTART</td>
        <td>Dynamic</td>
    </tr>
    <tr>
        <td><input type="checkbox" id="host3" name="host3"/>
        host3</td>
        <td>10.20.1.9</td>
        <td>C</td>
        <td>4</td>
        <td>BSTART</td>
        <td>Dynamic</td>
    </tr>
    <tr>
        <td><input type="checkbox" id="host4" name="host4"/>
        host4</td>
        <td>10.20.1.11</td>
        <td>C</td>
        <td>4</td>
        <td>BSTART</td>
        <td>Dynamic</td>
    </tr>

</tbody>
</table>

Note that the id and name of the checkbox coincide with the host name. Also note that the first td does not have a checkbox. That’s the expected behavior.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T16:48:11+00:00Added an answer on May 28, 2026 at 4:48 pm

    After lots of painful hours of digging up every small detail, I realized that my problem was not how I coded the thing, nor was it stuff like unexpected DOM changes, but a simple detail I failed to see:

    The id I was trying to assign to the checkbox contained a period (“.”) character.

    This causes lots of problems for jQuery when trying to look up that sort of id, because a period as-is acts as a class descriptor. To avoid this, the period character must be escaped using 2 backslashes.

    For example:

    $("#my.id")    // incorrect
    $("#my\\.id")  // correct
    

    So then the fix in my case would be:

    $myTable.find('#' + allTicks[i].replace(".", "\\.")).prop('checked', true);
    

    … and it finally works.

    Thanks everyone for all your helping hands!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
Does anyone know how can I replace this 2 symbol below from the string
I have some data like this: 1 2 3 4 5 9 2 6
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.