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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T14:53:37+00:00 2026-05-28T14:53:37+00:00

Not quite sure what’s going sideways here. The below function should clear all the

  • 0

Not quite sure what’s going sideways here.

The below function should clear all the rows and then create new rows, but while it does clear on-screen for a moment, it keeps the previous rows and appends to them.

Is this because of the use of appendTo? Why should it matter when it’s occurring after the rows have been cleared?

Is there another / better way to clear a table and write an array?

<script type="text/javascript">
    function buildrow(){
        $( "#oatable tbody tr" ).each( function(){
            this.parentNode.removeChild( this ); 
              });

        $('input:checkbox:checked').each(function() { 
                var idtofind = ($(this).attr('id'));
                //alert(idtofind);
                //alert(idtofind);          
                //Hide Content (this is sloppy but easy to customize..)
                //$(wrapper).hide();
                //('This is the first ' + idtofind);    
                //Get XML Data
                $.ajax({
                type: "GET",
                url: "xml/OA.xml",
                dataType: "xml",
                success: function(xml) {
                    var tablediv = $('div#table');
                    var xmlArr = [];
                    $(xml).find('OAData').each(function(){
                                                if($(this).attr('OAval')===idtofind) {
                            //alert('This is the next ' + idtofind);
                        var xml_OAval           = $(this).attr('OAval');
                        var xml_OAid            = $(this).find('OAid').text();
                        var xml_BAC_Level_1         = $(this).find('BAC_Level_1').text();
                        var xml_Basel_Level_1       = $(this).find('Basel_Level_1').text();
                        var xml_Basel_Level_2       = $(this).find('Basel_Level_2').text();
                        var xml_Risk_Category_Level_3   = $(this).find('Risk_Category_Level_3').text();
                        var xml_GTO_Library_Ref_ID  = $(this).find('GTO_Library_Ref_ID').text();
                        var xml_Ent_Lib_Ref_ID      = $(this).find('Ent_Lib_Ref_ID').text();
                        var xml_Name            = $(this).find('Name').text();
                        var xml_Description     = $(this).find('Description').text();
                        var xml_Potential_Risk_Event    = $(this).find('Potential_Risk_Event').text();
                        var xml_Cause           = $(this).find('Cause').text();
                        var xml_GTO_Library     = $(this).find('GTO_Library').text();
                        var xml_Comments        = $(this).find('Comments').text();
                        // Add matched items to an array
                        xmlArr += '<tr><td>';
                        xmlArr += xml_OAid;
                        xmlArr += '</td><td>';
                        xmlArr += xml_BAC_Level_1;
                        xmlArr += '</td><td>';
                        xmlArr += xml_Basel_Level_1;
                        xmlArr += '</td><td>';
                        xmlArr += xml_Basel_Level_2;
                        xmlArr += '</td><td>';
                        xmlArr += xml_Risk_Category_Level_3;
                        xmlArr += '</td><td>';
                        xmlArr += xml_GTO_Library_Ref_ID;
                        xmlArr += '</td><td>';
                        xmlArr += xml_Ent_Lib_Ref_ID;
                        xmlArr += '</td><td>';
                        xmlArr += xml_Name;
                        xmlArr += '</td><td>';
                        xmlArr += xml_Description;
                        xmlArr += '</td><td>';
                        xmlArr += xml_Potential_Risk_Event;
                        xmlArr += '</td><td>';
                        xmlArr += xml_Cause;
                        xmlArr += '</td><td>';
                        xmlArr += xml_GTO_Library;
                        xmlArr += '</td><td>';
                        xmlArr += xml_Comments;
                        xmlArr += '</td></tr>';

                        //alert(xmlArr);
                        }
                      }); // end each loop

                  //Append array to table (this way is much faster than doing this individually for each item)
                  //alert(xmlArr)
          $(xmlArr).appendTo("tbody#oa");
        } // end post AJAX call operaitons
        }); // end AJAX
            }

    );
    }
    </script>
  • 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-28T14:53:38+00:00Added an answer on May 28, 2026 at 2:53 pm

    To remove all the rows from a table tbody use this code.

    $("#oatable tbody tr").remove();
    

    .remove() reference: http://api.jquery.com/remove/

    In your ajax success handler you have defined xmlArr as an array and you are concatenating string to it which is not corerct. Use the push method to add string to it.

    success: function(xml) {
       var tablediv = $('div#table');
       var xmlArr = [];
       ....
       ....
       //xmlArr += '<tr><td>';
       //use push method
       xmlArr.push('<tr><td>');
       ....
       ....                    
       ....
       xmlArr.push('</td></tr>');
       ....
       ....
    
    
    
       //Finally use xmlArr.join('') to get the combined string
       $(xmlArr.join('')).appendTo("tbody#oa");
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Not quite sure how I should attack this. I need to create a Comparator
I'm not quite sure how I should get the top URL and then place
Not quite sure what's going on here but it seems as though Microsoft always
Not quite sure how to explain this but here goes. I have a function
I'm not quite sure when selecting only a certain number of rows would be
I'm not quite sure how to put this, but here goes... The css clip
I'm not quite sure of the terminology here so please bear with me.... Let's
I'm not quite sure how to do this in SQL. Here it is in
Having trouble here and not quite sure how to do it. I've attempted jQuery
I'm not quite sure if I can ask this question here or on SuperUser

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.