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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T19:22:50+00:00 2026-06-13T19:22:50+00:00

I have two textboxes and an add button. When you click add it generates

  • 0

I have two textboxes and an add button. When you click add it generates a table below the textboxes with each row having a Remove button. When you click remove it removes the table row but doesn’t remove the contents from within the array (at least i don’t think).

How do I get it to remove the contents as well? Currently when I click add and then remove a few it messes up my database table by inserting the first one fine but then messing up the rest by either not inserting it, or just adding 1 column…. If i don’t remove any it works perfectly fine.

 var $tdRemoveRow = $('<td>').appendTo($tr);
    $('<a>').attr({
        'href': '#',
    'id': 'submit-button'
    }).text("Remove").click(function() {
        $tr.remove();
        return false;
    }).appendTo($tdRemoveRow);

The error must be in the above code somewhere. Does anyone see an issue?

 var locations = [];   
$("#add").click(function() {
    var address = $("#address").val();
    var city = $("#city").val();

    if (address =="" || city =="") {
    $("#locationDeals").text('*Please enter an address and city');
    return false;
} 
else {
codeAddress();
        var $tr = $('<tr>').css({
            'padding': '4px',
            'background-color': '#ddd'
        }).appendTo('#locationDeals');

        var location = [
            address,
            city                
        ];
        locations.push(location);

        for (i = 0; i < 2; i++) {
            var $td = $('<td>').appendTo($tr);
            $('<span>').text(location[i]).appendTo($td);
            $('<input type="hidden">').attr({
                'name': 'loc[' + ctr + '][' + i + ']',
                'value': location[i]
            }).appendTo($td);
        }

        var $tdRemoveRow = $('<td>').appendTo($tr);
        $('<a>').attr({
            'href': '#',
        'id': 'submit-button'
        }).text("Remove").click(function() {
            $tr.remove();
            return false;
        }).appendTo($tdRemoveRow);

        ctr++;

        $("#locationtext").text('');
        return false;
    } 
});
  • 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-13T19:22:51+00:00Added an answer on June 13, 2026 at 7:22 pm

    When removing the row, use .splice to also remove it from the array:

    .click(function() {
        $tr.remove();
        locations.splice(locations.indexOf(location), 1);
        return false;
    })
    

    Note that this will not behave correctly if location is not inside locations, but with your code this is guaranteed not to be the case.


    You shuold decrement the indices in the input names as well (just before removing the tr):

    var index = $tr.index();
    $("#tableDailyDeals input[type='hidden']").each(function() {
        this.name = this.name.replace(/\[(\d+)\]/, function(str, number) {
          return "[" + (+number > index ? number - 1 : number) + "]";
        });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

hay, i have two textboxes i.e book_name and author and a button that save
I have two forms, one with a button 'Add' which loads the second form
I have two textboxes <input id='random_value' name='random_name' value='First' <input id='random_value' name='random_name' value='' I need
I have two textboxes for entering the name and price of an item, a
I'm using the jQuery datepicker where I have two textboxes (start date / end
I have two asp.net textboxes and need to put a validate function in javascript
I have two views 1 . Add.aspx 2. Change.aspx View Add has a TextBox
I have a form that consists of two data grids and a button. Datagrid
I have a gridview and i have two buttons edit and delete.Once i click
I have this code first the constructor and button click event: using System.Text; using

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.