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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T09:14:24+00:00 2026-06-12T09:14:24+00:00

I have a form inside a table. In that table I have row for

  • 0

I have a form inside a table. In that table I have row for input fields. I have two options for remove row and add line. In add line when user will click a new row will be added and when user will click on remove row the last row will be removed. All this is working fine. But I have a problem that suppose I have clicked on remove row option and the last row will be removed and in this way all the rows are removed. Again now when I am clicking on add line it is not adding a new row. So can some one solve this? Here is the complete code for this

<!DOCTYPE HTML>
<html lang="en-IN">
<head>
  <meta charset="UTF-8">
  <title></title>
</head>
  <script type="text/javascript" src="jquery1.7.2.js"></script>
<body>
<style type="text/css">
  table td {
    border: 1px solid #666;
  }
</style>
  <script type="text/javascript">
  jQuery(document).ready(function() {
    jQuery("#add-line").click(function() {
      var row = jQuery('.form-fields tbody>tr:last').clone(true);
      row.find("input:text").val("");
      row.insertAfter('.form-fields tbody>tr:last');
      return false;
    });
    jQuery('#remove-row').live('click',function(event){
      jQuery(this).parent().parent().remove();
    });
  });
</script>

  <div id="form">
  <table id="form-headings">
    <tr>
      <td width="15%">Remove Rows</td>
      <td width="15%">Product</td>
      <td width="16%">Description</td>
      <td width="13%">Unit Cost</td>
      <td width="14%">Quantity</td>
      <td width="12%">Discount</td>
      <td width="14%">Total</td>
    </tr>
  </table>
  <div class="row">
  <div class="form-fields">
    <table>
      <tr>
        <td><input type="button" id="remove-row" value="Remove Row" /></td>
        <td><input type="text" id="form_product" size="5px"/></td>
        <td><input type="text" id="form_description" size="5px"/></td>
        <td><input type="text" id="form_unit_cost" size="5px"/></td>
        <td><input type="text" id="form_quantity" size="5px"/></td>
        <td><input type="text" id="form_discount" size="5px"/></td>
        <td><input type="text" id="form_total" size="5px"/></td>
      </tr>
    </table>
  </div>
  </div>
  <input type="button" id="add-line" value="Add Line" />
  </div>
</body>
</html>
  • 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-12T09:14:24+00:00Added an answer on June 12, 2026 at 9:14 am

    That is because you do not have a tr able to clone when you delete the last row in the table.

    In the code you are cloning and then appending it to the table..

    UPDATED CODE

    Also this part of your code is wrong

    var row jQuery('.form-fields tbody>tr:last').clone(true);
    row.insertAfter('.form-fields tbody>tr:last');
    

    As once the last row is removed you wont find the tr>last .. It will return false.. So try avoiding it..

    You can create a dummy row that holds this row structure and clone it from there..

    I have created a .prototype class that holds the row.. Cloning it and inserting it..

    Check FIDDLE

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

Sidebar

Related Questions

I have a table inside a form that looks as follows: <td><input type=text name=code[0]
I have a form with the fields inside table cells. On the last column
I have a table inside a form. It has two columns, the first one
So I have a html page that has a form, and a table inside
I have form elements that are declared inside a table, who are inherently vertically
I have a table inside a form, which is populated with various input boxes.
I have a div inside of a table which is inside of a form
I have a page on a website that contains a secure form inside an
I have a webrequest that returns a html response which has form inside with
I have an ASP.NET Webform and inside the form I have an input type

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.