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 6202509
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T04:44:54+00:00 2026-05-24T04:44:54+00:00

For some reason it only removes the first row and not sure why. function

  • 0

For some reason it only removes the first row and not sure why.

function templatesArray(whatsThis) {
    var myNewArray = new Array(); 
    var aRow = new Array();

    $('input:checkbox[name="templates"]:checked').each(function(i) { 
        myNewArray.push($(this).val());
        aRow.push(oTable.fnGetPosition( $(this).parents('tr').get(0)));
    }); 
    var dataString = 'templatesArray=' + myNewArray + '&deleteTemplatesArray=True'; 
    $.ajax({ 
        type: "POST", 
        url: "processes/templates.php", 
        data: dataString,
        success: function(data) {
            if (data.errorsExist) {
            } else {
                $(whatsThis).parents("tr").eq(0).hide(); 
                for (i in aRow)  // loop over the array of row indexes
                  oTable.fnDeleteRow(aRow[i]);
                if(oTable.fnSettings().fnRecordsTotal() == 0) {
                    $('.bt_red').remove();
                    $('.bt_blue').remove();
                }
                if(oTable.fnSettings().fnRecordsTotal() <= 10) {
                    $('.bt_blue').remove();
                }
                if(oTable.fnSettings().fnRecordsTotal() <= 10) {
                    $('div.pagination').remove();
                }
            } 
        }
    });

}
  • 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-24T04:44:55+00:00Added an answer on May 24, 2026 at 4:44 am

    Avoid using for .. in on Arrays. You can get unexpected results. Instead use Array.foreach or jQuery’s $.each():

    $.each(aRow, function() {
        oTable.fnDeleteRow(this);
    });
    

    If that doesn’t fix it, please post more details, such as the code for oTable.fnDeleteRow(). Are any JavaScript errors being thrown?

    Edit: Your code is passing the row index to the delete function. After the delete function is called all proceeding rows have a new row index. So if you try to delete rows 1, 2, and 3, you’ll end up deleting rows 1, 3, and 5. Instead store and pass a reference to the row itself:

    $('input:checkbox[name="templates"]:checked').each(function(i) { 
        myNewArray.push($(this).val());
        aRow.push($(this).closest('tr')[0]);
    }); 
    

    http://jsfiddle.net/3Ldj5/2/

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

Sidebar

Related Questions

For some reason, siginterrupt() only seems to set the behaviour for the first signal
Theres some reason for this code not reach the first else? I got it
See code below, for some reason it only works when I put a breakpoint
For some reason, the Server control menu disappeared. The only menu appears on the
Have a simple form (only extract fields here) but for some reason the JQserilization
I have a problem with tinyMCE but only on live environment from some reason
I have trouble where, for some reason, SVN would only merge the newly generated
For some reason I never see this done. Is there a reason why not?
For some reason when I create a new namespace in Visual Studio 2008 its
I have this code, and for some reason my $.post function fires twice in

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.