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

  • Home
  • SEARCH
  • 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 8563037
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T16:52:04+00:00 2026-06-11T16:52:04+00:00

I have an Jquery script that loads an XML file and spits out the

  • 0

I have an Jquery script that loads an XML file and spits out the contents. However, I’d like to format these contents into a table, with 3 columns per row. Currently, it makes one long row and I haven’t found anything on google about calling in a new function after .each has loaded several items.

To reiterate, I want to execute function newrow() after if(hideproduct == “”){} has successfully executed 3 times.

var product_xml = "xml/products_loaded.xml"
function xmlParser() {
$.ajax({
    type: "GET",
    url: product_xml,
    dataType: "xml",
    success: function(xml) {

        function newrow(){
            $("#output").append("</tr><tr>")
        }

        $(xml).find("SAVED_EXPORT").each(function(){

            var productcode = $(this).find("productcode").text()
            var productname = $(this).find("productname").text()
            var productprice = $(this).find("productprice").text()
            var hideproduct = $(this).find("hideproduct").text()

            if(hideproduct == ""){
                $("#output").append("<td class='product' id='" + productcode + "'>"
                + "<a href='/i/" + productcode + ".htm' title='" + productname + ", " + productcode + "'>" + productname + "</a><br>"
                + "<span><font class='text colors_text'><b><span class='price'>Our Price</span>: </b></font> $" + productprice + "</span><br>"
                + "<img src='/v/vspfiles/photos/" + productcode + "-1.jpg' border='0' alt='" + productname + "'>"
                + "</td>");;

            }
        })      
    }
})
}

Thanks in advance for anyone who has an idea on how to solve this.

  • 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-06-11T16:52:05+00:00Added an answer on June 11, 2026 at 4:52 pm

    The key thing is that you need a counter variable outside of the .each to store state:

    var count = 0;
    

    since you can’t store state variables using local var declarations inside the .each callback function.

    Then, inside the if (hideproduct ...) block, count the number of times it was called:

    ++count;
    

    and if necessary, call the function

    if (count === 3) {
        newRow();
        count = 0;
    }
    

    As it happens your newRow() function won’t work anyway, because you can’t create unbalanced HTML tags using .append.

    A better solution would be:

    var tr = null;
    var count = 0;
    
    $(xml).find("SAVED_EXPORT").each(function() {
         if (hideproduct === "") {
             if (tr === null) {    // create a new row
                 tr = $('<tr>').appendTo('#output');
             }
    
             tr.append(...);       // add your content
    
             if (++count % 3 === 0) {
                 tr = null;        // force a new <tr> on the next iteration
             }
         }
    });
    

    Note how a new <tr> is only created when necessary, and then the new content in your <td> elements are added directly to that, and not to #output.

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

Sidebar

Related Questions

I have a jQuery tab script that gets content from a PHP file defined
I have made a jQuery script that loads items from the database when the
i have a jquery script. see fiddle here , that loads some scripts depending
I have a php script that reads an XML file and modifies it with
I have a PHP script that loads XML content dynamically: require_once 'directory/directory/'; $nice= '1149632';
I have a JS/jQuery script that adds our leads (web contacts) to the DOM
I have a script on jquery that load some site in iframe using: $(#demo_frame).attr('src',
I have a jQuery script that polls my server for new data, but it
I have this jQuery script that works fine: $(select).change(function () { var finalPrice =
I have a simple jQuery script that I'm trying to build upon but I

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.