How to get jQuery UI Datepicker selected date to a PHP Session variable when a date selected by user?
4
-
3Yes. Ask a yes/no question, get a yes/no answer.DaveRandom– DaveRandom2012-02-06 11:33:12 +00:00Commented Feb 6, 2012 at 11:33
-
3Related question with good answer: stackoverflow.com/questions/607673/…Anders Arpi– Anders Arpi2012-02-06 11:33:49 +00:00Commented Feb 6, 2012 at 11:33
-
1additionally you can utilize select event of the DatePicker UI to set the session using jquery.ajax or jquery.post whatever way you like to call the pageDevjosh– Devjosh2012-02-06 11:38:32 +00:00Commented Feb 6, 2012 at 11:38
-
@DaveRandom Question edited... :)Nalaka526– Nalaka5262012-02-06 11:38:41 +00:00Commented Feb 6, 2012 at 11:38
Add a comment
|
2 Answers
Make an AJAX call when the onSelect is trigged.. Just dummy code you can play with:
$('.selector').datepicker({
onSelect: function(dateText, inst) {
$.ajax({
url: "myPHPscript.php?selecteddate=" + dateText,
success: function(){
$(this).addClass("done");
}
});
}
});
2 Comments
Simon Edström
I dont know PHP but I give it a try. Create a file that is called myPHPscript.php and use: echo $_GET['selecteddate'];
Simon Edström
The selecteddate variable will be passed thru QueryString ditio.net/2008/06/12/php-query-string
Description
You can do this using Ajax. After the Datepicker is closed you can set the Session Variable using a Ajax call.
You can use the DatePicker event onClose if you want to set the variable after the dialog is closed or onSelect after a date is selected. I would prefer the onClose event.
Sample
jQuery
$('.selector').datepicker({
onClose: function(dateText, inst) {
$.post("/backend.php", {"VariableName": dateText});
}
});
PHP (backend.php)
<?php
// set the variable
$_SESSION['VariableName'] = $_POST['VariableName'];
?>