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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T06:03:25+00:00 2026-06-14T06:03:25+00:00

This is connected to my previous question: How to add onclick function for programmatically

  • 0

This is connected to my previous question: How to add onclick function for programmatically created button.

Now, I currently have a form with two textboxes, a button and a hidden table. When the button is clicked, the table is displayed and a row is added with the values of the textboxes on two columns and a remove button the third. I am now able to remove selected rows when the remove button is clicked. My new problem is how can I get the data of the first and second column so I can update the database?

I use JSON to update the database. Here’s the code I currently have:

$("#addToDisplay").click(function (event) {
    $("#tblProducts").removeClass("hide");
    var counter = 1;
    event.preventDefault();
    counter++;
    var prod = {prodName: $("#txtProducts").val(), prodQty: $("#txtQty").val()}
    $.ajax({
        type: "POST",
        traditional: true,
        url: "/Service/JsonUpdateProduct",
        dataType: "json",
        data: prod,
        success: function (result) {
            var newRow = "<tr><td id='rowProd" + counter + "'>" + $("#txtProducts").val() + "</td><td id='rowQty" + counter + "'>" + $("#txtQty").val() + "</td><td><input type='button' value='Remove' id='btnRemove" + counter + "' class='remove' /></td></tr>";
            $("#tblProducts").append(newRow);

            $("#tblProducts").on("click", ".remove", function () {
                $(this).closest("tr").remove();
                var rowCount = $("#tblProducts tr").length;
                var removeProd = {revertName: $("#rowProd" + counter).val(), revertQty: $("#rowQty" + counter).val()}
                $.ajax({
                    type: "POST",
                    traditional: true,
                    url: "/Service/JsonRemoveProduct",
                    dataType: "json",
                    data: removeProd,
                    success: function (result) {
                        if (rowCount == 1) {
                            $("#tblProducts").addClass("hide");
                        }
                    }
                });
                $("#productQty").val("");
                $("#autoCompleteText").val("");
            });
        }
    });
});

I’ve been trying that code but all I get is a null value for the quantity which causes an error. So how do I exactly get the data of the selected ProductName and Quantity from a selected row?

I basically am trying to get something like this:

var data = { prodName: $("#selectedRowCell1")}

so I can pass it to the method in my class and update the database.

Also, is it possible to get the current Id of a different table and insert it to another table + 1. Something like this:

Select id from Details
then
Update Products set detailId = Details.id + 1

? I know this doesn’t work as I’ve already tried it. So is something like this even possible?

  • 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-14T06:03:26+00:00Added an answer on June 14, 2026 at 6:03 am

    First, these should be separate click events, don’t define a click event within the ajax callback. This is why you use the on() method. .on() acts as a event delegator. The selector is a static element bound to the document on page load and not after. This means, we can bind events to this parent element, and their children will have the event delegated to them if supplied as the 2nd argument.

     $("#addToDisplay").click(function (event) {
        //nothing to change here, omitted for length
     }); 
    

    Here, the issue is how to get productData. By your definition, product data are the two previous columns in the row when the .remove class element is clicked. Let’s do it.

    $("#tblProducts").on("click", ".remove", function() {
        //when you do the following, you remove the entire row we need
        //lets not do that yet.
        //$(this).closest("tr").remove();
    
        var $this = $(this); //cachable -- save some performance, reference success
    
        var col1 = $this.closest('tr').find('#rowProd').text(), // first column
            col2 = $this.closest('tr').find('#rowQty').text(), //second column
            productData = { 'product' : col1, 'quantity' : col2};
    
        //now productData is properly populated with the values we need.
    
        $.ajax({
            type: "POST",
            traditional: true,
            url: "/Service/JsonRemoveProduct",
            dataType: "json",
            data: productData,
            success: function(result) {
    
                //ajax successful, NOW we'll remove the row.      
                $this.closest("tr").remove();
    
                if ($this.find('tr').length;) {
                    $("#tblProducts").addClass("hide");
                }
            }
        });
        $("#txtQty").val("");
        $("#txtProducts").val("");
    });​
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is an interview question. I have K machines each of which is connected
This is a more concrete question that is connected with my previous one. I
This is connected with my previous question as it's dealt with the same piece
Apologies, but I have searched and read previous answers on this question but couldn't
This leads on from my previous question here . I have been developing with
My previous question on the same theme: C#: Asynchronous NamedPipeServerStream understanding Now I have
While I have already solved this issue in a previous question using a native
(This question is loosely related to my previous question ) Hello there. I have
This question directly relates to my Previous Question . I have a need to
This question is connected to my other question but I changed the logic a

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.