I'm trying to make it so that when my image is clicked, it opens a calendar and when the date is picked on the calendar, make it update my database with the new date using my AJAX method. *Just to note, my code does with with normal html text updatings in the database. I just need help with getting calendars to update the database using it.
My code is below :
HTML CODE
<td style="border: 1px solid #eee; text-align: center; font-size: 11px;" contenteditable="false" onBlur="saveToDatabase(this,'time','<?php echo $faq[$k]["id"]; ?>')" onClick="showEdit(this);">
<?php echo $faq[$k]["time"] != '' ? $faq[$k]["time"] : 'None'; ?>
<input type="hidden" id="datepicker">
AJAX CODE
function showEdit(editableObj) {
$(editableObj).css("background","#FFF");
}
function saveToDatabase(editableObj,column,id) {
$(editableObj).css("background","#FFF url('images/spin.gif') no-repeat right");
$.ajax({
url: "includes/saveedit_members.php",
type: "POST",
data:'column='+column+'&editval='+editableObj.innerHTML+'&id='+id,
success: function(data){
window.location.replace("admin_members.php");
}
});
}
JAVASCRIPT
<script>
$(function() {
$("#datepicker").datepicker({
showOn: 'button',
buttonImage: 'http://theonlytutorials.com/demo/x_office_calendar.png',
buttonImageOnly: true,
changeMonth: true,
changeYear: true,
showAnim: 'slideDown',
duration: 'fast',
dateFormat: 'dd-mm-yy'
});
});
</script>
PHP Receiving code
if(!isset($_POST['column']) || !isset($_POST["editval"]) || !isset($_POST["id"])) {
header('Location: error-pages/index.php');
} else if(isset($_POST['column']) && isset($_POST["editval"]) && isset($_POST["id"])) {
mysqli_query($con, "UPDATE users set " . $_POST["column"] . " = '".$_POST["editval"]."' WHERE id=".$_POST["id"]);
}
Remember, I'm just needing help making it so it updates my database when my desired date is clicked.
An example image of what it looks like :