I have the following function which allows me to double click on content within a table and edit it. The problem I am having now is I am unsure how to implement the function to update in the database so the changes stay once I press enter.
UPDATE:
I have the following but it is not posting to the php file
PHP
include("../../db.php");
$requestHandled = "UPDATE requests SET Status = 1 WHERE RequestID = '".$_POST['RequestID']."'";
mysqli_query($requestHandled) or die(mysql_error());
HTML
<td class="RequestID"><?php echo $id; ?></td>
<td class="Address"><?php echo $addr; ?></td>
<td><?php echo $sub; ?></td>
<td><?php echo $info; ?></td>
<td><?php echo $date; ?></td>
Jquery:
$(function () {
$(".Address").dblclick(function () {
var OriginalContent = $(this).text();
$(this).addClass("cellEditing");
$(this).html("<input type='text' value='" + OriginalContent + "' />");
$(this).children().first().focus();
$(this).children().first().keypress(function (e) {
if (e.which == 13) {
var newContent = $(this).val();
$(this).parent().text(newContent);
$(this).parent().removeClass("cellEditing");
}
});
$(this).children().first().blur(function(){
$(this).parent().text(OriginalContent);
$(this).parent().removeClass("cellEditing");
});
$(this).find('input').dblclick(function(e){
e.stopPropagation();
});
});
});
$('.Address').keypress(function (e) {
var key = e.which;
if(key == 13) // the enter key code
{
jQuery.ajax({
url: "functions/updateAddress.php",
type: "POST",
data: {RequestID: $('.RequestID').text(), Address: $('.Address').text()},
success: function(response)
{
alert("Updated Address!");
}
});
}
});
jquery ajax