Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to remove a row from a table
    text
    copied!<p>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: </p> <p>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.</p> <p>I found the following post from someone else on stackoverflow: <a href="https://stackoverflow.com/questions/2161991/how-to-remove-current-row-from-table-in-jquery">How to remove current row from table in jQuery?</a></p> <p>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. </p> <pre><code> &lt;table class="table table-bordered table-striped" id="databaserecords"&gt; &lt;thead&gt; &lt;tr&gt; &lt;th&gt;Id&lt;/th&gt; &lt;th&gt;Name&lt;/th&gt; &lt;th&gt;Status&lt;/th&gt; &lt;th&gt;Voice&lt;/th&gt; &lt;th&gt;Jumbo&lt;/th&gt; &lt;th&gt;Mode&lt;/th&gt; &lt;th&gt;&amp;nbsp;&lt;/th&gt; &lt;/tr&gt; &lt;/thead&gt; &lt;tbody&gt; &lt;?php foreach ($dblist as $record): ?&gt; &lt;tr&gt; &lt;td class ='recordId'&gt;&lt;?php echo $record['Id'] ?&gt;&lt;/td&gt; &lt;td class ='recordName'&gt;&lt;?php echo $record['Name'] ?&gt;&lt;/td&gt; &lt;td&gt;&lt;?php echo $record['Status'] ?&gt;&lt;/td&gt; &lt;td&gt;&lt;?php echo $record['Voice'] ?&gt;&lt;/td&gt; &lt;td&gt;&lt;?php echo $record['Jumbo'] ?&gt;&lt;/td&gt; &lt;td class='recordmode'&gt;&lt;?php echo $record['Mode'] ?&gt;&lt;/td&gt; &lt;td&gt;&lt;button id="deleteRecord"&gt;Delete Record&lt;/button&gt;&lt;/td&gt; &lt;/tr&gt; &lt;?php endforeach ?&gt; &lt;script&gt; $('#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 &gt; 1) { $thevalueIwanttoSave = $(this).closest('recordId').val(); alert($thevalueIwanttoSave); } }); &lt;/script&gt; </code></pre> <p>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. </p> <p>Thanks. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload