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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T10:15:24+00:00 2026-06-18T10:15:24+00:00

An $.ajax function is returning some data that I’m putting into a table within

  • 0

An $.ajax function is returning some data that I’m putting into a table within the success function.

Here’s how I’m building the table rows:

$.each(branchList, function(index,element) {
    $('table#tblViewEditAllBranches tbody').append('<tr class="viewEditRow">' +
        '<td class="deleteBranch">' +
            '<input type="checkbox" class="chkDeleteBranch" name="deleteBranches[]" value="' + element['id'] + '" /><br />' +
            '<input type="submit" class="cancelListEditBranch edit hideOnLoad" value="Cancel" title="Cancel editing this branch" /><br />' +
            '<input type="submit" class="submitListEditBranch edit hideOnLoad" value="Save" title="Save the changes" />' +
        '</td>' +
        '<td class="viewEditBranchName">' +
            '<label class="viewBranchName detailDisplay">' + element['name'] + '</label>' +
            '<input type="text" class="edit editBox editName hideOnLoad" value="' + element['name'] + '" /><br /><br />' +
            '<label id="lblBranchesListEditError" class="errorMsg"></label>' +
        '</td>' +
        '<td class="viewEditBranchUrl">' +
            '<label class="viewBranchUrl detailDisplay"><a href="#" class="branchDetailLink" title="Click to go the branch\'s web page">' + element['url'] + '</a></label>' +
            //'<label class="viewBranchUrl detailDisplay">' + element['url'] + '</label>' +
            '<input type="text" class="edit editBox editUrl hideOnLoad" value="' + element['url'] + '" />' +
        '</td>' +
    '</tr>');
    // Get the first part of the url
    var targetFolder = BuildUrlTargetFolder();
    console.log('full url:' + targetFolder + '/index.php/coverage-area/' + element['url']); // Displays correct url for the current branch
    // Set the href attribute for the branch link otherwise have an empty anchor tag
    if (element['url'] !== '') {
        $(this).find('tr a.branchDetailLink').attr('href', targetFolder + '/index.php/coverage-area/' + element['url']);
    } else {
        $(this).find('tr a.branchDetailLink').attr('href', '#');
    }
});

As you can see, at the bottom of the code, before the the iteration to the next table row, I’m building the link and then I’m trying to set the href attribute.

As the code currently is, the console output is showing the correct url as each row is iterated through. But, what’s happening is all of the href attributes are getting set to the last url that is retrieved. So, in each iteration, the code sets all links in the table to the current url.

I’ve tried finding the correct selector for the if/else block by changing the selector and checking the console output, but I can’t get it.

I think all I need to do is to get the selector right in the if/else block so it only sets the href attribute for the current row.

  • 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-18T10:15:26+00:00Added an answer on June 18, 2026 at 10:15 am

    Why not build the URL first and then append it as you are adding the HTML? That way you dont have to select on the DOM to find the link.

    Also selecting the table outside of the each will give you speed boosties.

      var myTable = $('table#tblViewEditAllBranches tbody');
      $.each(branchList, function(index,element) {
    
            // Get the first part of the url
            var targetFolder = BuildUrlTargetFolder();
            var branchUrl = '#';
            console.log('full url:' + targetFolder + '/index.php/coverage-area/' + element['url']); // Displays correct url for the current branch
            // Set the href attribute for the branch link otherwise have an empty anchor tag
            if (element['url'] !== '') {
                branchUrl =  targetFolder + '/index.php/coverage-area/' + element['url'];
            }
    
            myTable.append('<tr class="viewEditRow">' +
                '<td class="deleteBranch">' +
                    '<input type="checkbox" class="chkDeleteBranch" name="deleteBranches[]" value="' + element['id'] + '" /><br />' +
                    '<input type="submit" class="cancelListEditBranch edit hideOnLoad" value="Cancel" title="Cancel editing this branch" /><br />' +
                    '<input type="submit" class="submitListEditBranch edit hideOnLoad" value="Save" title="Save the changes" />' +
                '</td>' +
                '<td class="viewEditBranchName">' +
                    '<label class="viewBranchName detailDisplay">' + element['name'] + '</label>' +
                    '<input type="text" class="edit editBox editName hideOnLoad" value="' + element['name'] + '" /><br /><br />' +
                    '<label id="lblBranchesListEditError" class="errorMsg"></label>' +
                '</td>' +
                '<td class="viewEditBranchUrl">' +
                    '<label class="viewBranchUrl detailDisplay"><a href=' + branchUrl + ' class="branchDetailLink" title="Click to go the branch\'s web page">' + element['url'] + '</a></label>' +
                    '<label class="viewBranchUrl detailDisplay">' + element['url'] + '</label>' +
                    '<input type="text" class="edit editBox editUrl hideOnLoad" value="' + element['url'] + '" />' +
                '</td>' +
            '</tr>');
    
        });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jquery-ajax function that sends data to a php script and the
I am wanting to use the AJAX function via jQuery to return some data
I've built some ajax that is returning part of a product catalog, and I'm
I have a javascript function which asks for some ajax data and gets back
I execute an ajax function that takes 3 seconds + so in this time
I've been making some ajax function these days, and I'm facing a small problem.
I am trying to do a simple AJAX function to send data from query
I need to return some data from a web service that looks something like
I'm experiencing something odd here, that I don't recall ever running into. I'm doing
I have the following JSON: {COLUMNS:[ID,FIRSTNAME],DATA:[[1,Steve],[2,Jim],[3,Bill],[4,Tony]]} I am trying to write some jQuery that

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.