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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T13:12:57+00:00 2026-05-31T13:12:57+00:00

I have a table inside a form that looks as follows: <td><input type=text name=code[0]

  • 0

I have a table inside a form that looks as follows:

<td><input type="text" name="code[0]" id="code[0]"/></td>
<td><input type="text" name="name[0]" id="name[0]"/></td>
<td><input type="text" name="cost[0]" id="cost[0]"/></td>
<td><input type="text" name="quantity[0]" id="quantity[0]"/></td>
<td><input type="text" name="total[0]" id="total[0]" value=""/></td>

When the code changes, the name and cost should change according, the data is re-fetched form the server. That I have done.
One can delete a given row while at any given row by clicking the row. I need to get the row column and attach the delete command,which remove the selected row and re-update the remaining rows with the respective data.
My challenge is getting the correct row and column to update.

This is what I have done:

<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>JSP Page</title>
    <link href="jquery-ui.css" type="text/css"/>
    <script src="jquery.js" type="text/javascript"></script>
    <script src="jquery-ui.js" type="text/javascript"></script>
    <script>

        function addRow(){
            var n=$("#itemsTable tbody tr").length;
            var tds="<tr id='row"+n+"'>";
            tds+="<td><img src='ico.ico' onclick='removeRow(this);'/></td>";
            tds+="<td><input type='text' name='code' id='code' onchange='searchByCode(this);'/></td>";
            tds+="<td><input type='text' name='name' id='name' onkeyup='search(this);'/></td>";
            tds+="<td><input type='text' name='cost' id='cost' onchange='rowTotal(this);'/></td>";
            tds+="<td><input type='text' name='quantity' id='quantity' onchange='rowTotal(this);'/></td>";
            tds+="<td><input type='text' name='value' id='value' readonly/></td>";
            tds+="</tr>";
            $("#itemsTable tbody").append(tds);
            init();
        }
        function search(row){
            $('#name').autocomplete('product/autocomplete',function(data){
                //update this row
                var products=data['details'];
                for(var i=0;i<products.length;i++){
                    var product=products[i];
                    $('#code').val(product.code);
                    $('#name').val(product.name);
                    $('#cost').val(product.cost);
                }

            }); 
        }
        function searchByCode(row){
            var code=$(row).$('#name').val();
            $.getJSON('product/searchbycode',function(data){
                //update this row
                var products=data['details'];
                for(var i=0;i<products.length;i++){
                    var product=products[i];
                    $('#code').val(product.code);
                    $('#name').val(product.name);
                    $('#cost').val(product.cost);
                }

            }); 
        }
        function init(){
            //this is just to give an idea or the rows, but are added dynamically
            var rows=$("#itemsTable tbody tr").length;
            for(var i=0;i<=rows;i++){
                $("input[name='code']").val(1001);
                $("input[name='name']").val("Bread");
                $("input[name='cost']").val(40);
                $("input[name='quantity']").val(1);
            } 
        }
        function removeRow(row){
            $(row).closest('tr').remove();
        }
        function rowTotal(row){
            var rowindex=$(row).closest('tr').index();
            //how do i get the row values here
            var value=0;
            var cost=parseFloat($("input[name='cost']").val());
            var quantity= parseFloat($("input[name='quantity']").val());
            value=cost*quantity;
            $("input[name='value']").val(value.toFixed());

        }
        function sumTotal(rows){
            var rows=$('#itemsTable tbody tr').lenght;
            var value=0;
            //i ca
            for(var i=0;i<rows;i++){
                var cost=parseFloat($("input[name='cost']").val());
                var quantity= parseFloat($("input[name='quantity']").val());
                value=cost*quantity;
                $("input[name='sum']").val()
            }
        }
    </script>
    <script>
        $(document).ready(function(){
            var i=0;
            while(i<4){
                addRow();i++;
            }
        });
    </script>
</head>

<body>
    <table id="itemsTable">

        <thead></thead>
        <tbody></tbody>
        <tfoot><input type='text' value='0' id='sum'name="sum" /></tfoot>
    </table>
</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-05-31T13:12:58+00:00Added an answer on May 31, 2026 at 1:12 pm

    Do this:

    ​$("tr").click(function() {
        alert("deleting row "+$(this).index());
        $(this).remove();
    });​​​​
    

    Heres a live example on jsFiddle.

    If you want do actually add the delete button to each row and have that button delete the row use this code:

    $(function() {
    
    window.deleteParentTr = function(theThis) {
        $(theThis).closest('tr').remove();
    };
    $("tr").append("<td><input value='delete' type='submit' onclick='window.deleteParentTr(this);' /></td>");    
    });
    

    ​And the live example for that is here

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

Sidebar

Related Questions

I have a simple form method... <form method=POST action=j_security_check> <table> <tr> <td>Name:</td> <td><input type=text
I have a small form inside a table. POSTing that form creates a new
So I have a html page that has a form, and a table inside
I have a table inside a form, which is populated with various input boxes.
Does this code contain anything invalid. I have a form with a table inside.
I have a div inside of a table which is inside of a form
I have a html page that looks like: <html> .. <form post=/products.hmlt ..> ..
I have a raw form-data that look like this: ------------V2ymHFg03ehbqgZCaKO6jy Content-Disposition: form-data; name=intro O
i have an html table inside a form in an asp.net mvc view. I
I have a table that contains form elements that I need to replace if

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.