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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T11:01:37+00:00 2026-05-18T11:01:37+00:00

Basically, I’ve got a table displays a few rows with a delete button next

  • 0

Basically, I’ve got a table displays a few rows with a delete button next to them. When someone clicks on the delete button, I take the ID of that button, pass it to a php script, delete the record from the database, and then fade the row out from the page. Here’s the code:

$(".remove-button").live('click', function(){
     var remove_ptype = encodeURIComponent($(this).attr("id"));

     $.ajax({
      type: "POST",
      dataType : "html",
      url: "script.php",
      data: "id of remove button goes here",
      success: function(msg){
      //Do nothing
       }
      });
     $(this).parent().parent().fadeOut(500);
     });

OK, next step. Also have an add button, which opens up a dialogue, which then processes a script, returns some data and appends appends another row for the data entered. This script also returns an id for the delete button just which would then be used by the above code. Here’s the appending code:

$("<tr>" +
         "<td>" + unescape(name) + "</td>" + 
         "<td width=\"250\">" + "<img src=\"" + siteurl + "/images/x-button.png\" id=\"" + name_id + "\" class=\"remove-button\" width=\"20\">"+ "</td>" + 
        "</tr>").appendTo( "#ptypes tbody" );

So this works beautifully so far. Now when I try to delete this newly added row without refreshing the page, it does get removed from the screen just fine, but I am unable to pick up the ID of this newly appended .remove-button and pass it to my php script. I know it’s possible as I’ve seen it done before in other applications (like basecamp). So, can anyone please guide me on how I can accomplish this?

FYI, I’m using JQuerUI to create the dialogue box, etc.

Thanks so much for your help!


ADDITION TO ORIGINAL MESSAGE

OK so the ID was indeed not showing up. I’ve got it to show up and it works, but I still have an issue. Here is the code for my jQUERY:

$( "#add-type-form" ).dialog({
                            autoOpen: false,
                            height: 350,
                            width: 500,
                            modal: true,
                            buttons: {
                                "Add": function() {
                                    var type_name = encodeURIComponent($('#type_name').attr('value'));
                                    var type_id = '';
                                    if (type_name != "") {  
                                        //Submit form
                                        $.ajax({
                                        type: "POST",
                                        dataType : "html",
                                        url: "script.php",
                                        data: "f=1" + "& ff=2" + "MORE STUFF",
                                        success: function(msg){
                                        types_id = msg;
                                        }
                                        });
                                        type_id = types_id;
                                        //Append to display                                         
                                        $("<tr>" +
                                                "<td>" + unescape(type_name) + "</td>" + 
                                                "<td width=\"250\">" + "<img src=\"" + siteurl + "/images/x-button.png\" id=\"" + type_id + "\" class=\"remove-type-button\" width=\"20\">"+ "</td>" + 
                                            "</tr>").appendTo( "#ptypes tbody" );
                                        $( this ).dialog( "close" );
                                    }},
                                Cancel: function() {
                                    $( this ).dialog( "close" );
                                }
                            },
                            close: function() {
                                allFields.val( "" ).removeClass( "ui-state-error" );
                            }
                        });

So this is a JQUERYUI diagloue, which basically processes the script, returns the id that I want to assign to my img tag. The trouble is, that the add button has to be pressed twice for some reason. If I remove the line where I assign a value to my type_id varaible after the ajax function, i.e.:

type_id = types_id;

I can’t get the type id. If the line stays in there, the add button has to be clicked twice. I’m not sure why that’s happening. I am sure that it is my lack of JS knowledge, so I’m seeking help because I don’t see anything wrong with the variable declaration per se.

Thanks again!

  • 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-18T11:01:38+00:00Added an answer on May 18, 2026 at 11:01 am

    This question seems pretty related to what you’re doing: jquery Find ID of dynamically generated tr tag

    The code mentioned looks like this, but I think you can rewrite it to your needs:

    $("a[href='delete.php']").click(function(e){
       var tr = $(this).closest('tr'),
           id = tr[0].id;
    
       // Put your AJAX call here
       $.post('/delete/' + id, function(){
           // Animate up, then remove
           tr.slideUp(500, function(){
              tr.remove();
           });
       });
    
    });
    

    If you’re running Chrome or Firefox, are you even able to see the id of the button in the first place? It could be that it isn’t even being appended…

    Good luck!


    It looks like you are not waiting for a response to your query, which is probably why you have to click the button twice. I’ve hacked together a (hopefully working) version of your script that waits for the query to finish before closing the dialog and doing all of that other clockwork:

    $("#add-type-form").dialog({
        autoOpen: false,
        height: 350,
        width: 500,
        modal: true,
        buttons: {
            "Add": function() {
                var type_name = encodeURIComponent($('#type_name').attr('value'));
                var type_id = '';
                var this_old = $(this); // Because $(this) won't really work inside of a anonymous function, you have to back up the original $(this) to another variable.
    
                if (type_name != "") {
                    //Submit form
                    $.ajax({
                        type: "POST",
                        dataType: "html",
                        url: "script.php",
                        data: "f=1" + "& ff=2" + "MORE STUFF",
                        success: function(msg) {
                            types_id = msg; // I'm not exactly sure if you need these two lines, but I'll keep them here anyways.
                            type_id = types_id;
    
                            //Append to display                                         
                            $("<tr>" + "<td>" + unescape(type_name) + "</td>" + "<td width=\"250\">" + "<img src=\"" + siteurl + "/images/x-button.png\" id=\"" + type_id + "\" class=\"remove-type-button\" width=\"20\">" + "</td>" + "</tr>").appendTo("#ptypes tbody");
                            this_old.dialog("close");
                        }
                    });
                }
            },
            Cancel: function() {
                $(this).dialog("close");
            }
        },
        close: function() {
            allFields.val("").removeClass("ui-state-error");
        }
    });
    

    Maybe this would work?

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

Sidebar

Related Questions

Basically, so far I've just got an add and minus button which will change
Basically I'm going to go a bit broad here and ask a few questions
Basically I’ve heard that certain conditions will cause .NET to blow past the finally
Basically I'm trying to accomplish the same thing that mailto:bgates@microsoft.com does in Internet Explorer
Basically I need to open a login window in a popup, so that it
Basically, I have a table. Onload, I set each row of the table to
Basically what I want to do it this: a pdb file contains a location
Basically, something better than this: <input type=file name=myfile size=50> First of all, the browse
Basically I have some code to check a specific directory to see if an
Basically, I would like a brief explanation of how I can access a SQL

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.