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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T02:36:26+00:00 2026-06-12T02:36:26+00:00

I have an html table, and on each row, i would like to add

  • 0

I have an html table, and on each row, i would like to add a delete button.
When the user clicks on it, I would like to do two things:

1) remove the row from the table.
2) extract data from the row that was removed – a particular cell, and then make an ajax call using this value to a function that will remove the record from the database. The function returns a fresh list of items, which i will then use to redisplay the same table.

I found the following post from someone else on stackoverflow:
How to remove current row from table in jQuery?

So I guess that addresses point number one. But I don’t know how to modify the code in the selected answer of the post to allow for grabbing the id value in the row, and then making an ajax call.

      <table class="table table-bordered table-striped"  id="databaserecords">
      <thead>
          <tr>
              <th>Id</th>
              <th>Name</th>
              <th>Status</th>
              <th>Voice</th>
              <th>Jumbo</th>
              <th>Mode</th>
              <th>&nbsp;</th>
          </tr>
      </thead>
      <tbody>

          <?php foreach ($dblist as $record): ?>
              <tr>          
              <td class ='recordId'><?php echo $record['Id'] ?></td>
              <td class ='recordName'><?php echo $record['Name'] ?></td>
              <td><?php echo $record['Status'] ?></td>
              <td><?php echo $record['Voice'] ?></td>
              <td><?php echo $record['Jumbo'] ?></td>
              <td class='recordmode'><?php echo $record['Mode'] ?></td>
              <td><button id="deleteRecord">Delete Record</button></td>
            </tr>
          <?php endforeach ?>


 <script>

    $('#deleteRecord').live('click', function()  {

                //get a count of all records. only allowed to delete if you have more than one record.
                var recCount = $('#databaserecords tbody tr').length;

                if (recCount > 1)
                {
                    $thevalueIwanttoSave = $(this).closest('recordId').val();
                                alert($thevalueIwanttoSave);
                            }

    });

 </script>

Right now, the alert always says that my variable is undefined.
Can you point me in the right direction? I do know how to code an ajax call… I think I just need help with grabbing the value from the table.

Thanks.

  • 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-12T02:36:27+00:00Added an answer on June 12, 2026 at 2:36 am

    You selector is not correct.

    $thevalueIwanttoSave = $(this).parent().siblings('.recordId').text();
    

    closest selects the closest parent of the element(recordId is not parent/grandparent or.. of your button element) and you have also missed a . for class selector. val is used for getting/setting values of form elements, for td elements you should use text or html method. Also note that IDs must be unique(you can use classes instead) and live method is deprecated, you can use on method.

    $('#databaserecords').on('click', '.deleteRecord', function() { 
    
        var recCount = $('#databaserecords tbody tr').length;
    
        if (recCount > 1) {
            var text = $(this).parent().siblings('.recordId').text();
            alert(text);
            // $(this).closest('tr').remove()
        }
    
    });​
    
    • siblings()
    • parent()
    • closest()
    • text()
    • on()
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a HTML table where each row has two columns. First column is
I have HTML table. I'm looping through table and iterate over each row whose
I have an HTML table where the first cell of each row contains text
I have an HTML table where each row has buttons which toggle status bits
I have the following table format and would like to be able to add
I have an HTML table with columns of input boxes, and would like the
I have a html table in which each line ( <tr> ) represents a
I have a HTML table. Each cell has content of different length. For this
I have my html table, and I want to specify the height of each
see fiddle i have html table and one textbox and one button.make cell selection

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.