As the title says, I was wondering if there is any way to create a function in JavaScript that will delete a row from a table? Maybe by calling some PHP to delete a row in the table?
3
-
Start with reading a book about it. Cures the wondering disease. ;)hakre– hakre2012-03-06 12:15:46 +00:00Commented Mar 6, 2012 at 12:15
-
I find solution. Thanks anyway!Marko Vasic– Marko Vasic2012-03-06 12:16:24 +00:00Commented Mar 6, 2012 at 12:16
-
A little hint: You'll find both parts answered on this site. So if you split the question and search for each part you'll find useful stuff.hakre– hakre2012-03-06 12:16:43 +00:00Commented Mar 6, 2012 at 12:16
Add a comment
|
2 Answers
For example if you have a table with a few columns, add a new column with some delete me button:
<tr rel="34">
<td>34</td>
<td>Joe</td>
<td><a class="deleteRow" href="#">delete me</a></td>
</tr>
Then in jQuery for example add a click event to .deleteRow class:
$('.deleteRow').click(function(){
var parent = $(this).parent('tr');
var rowId = parent.attr('rel');
$.ajax({
type: 'post',
url: "delete.php",
data: {id:rowId},
success: function(){
parent.remove();
}
});
});
And in delete.php script:
if ( $_SERVER['REQUEST_METHOD'] == 'POST' ) {
$id = (int) $_POST['id'];
// make sql query to remove element with given id
}