2

How to get jQuery UI Datepicker selected date to a PHP Session variable when a date selected by user?

4
  • 3
    Yes. Ask a yes/no question, get a yes/no answer. Commented Feb 6, 2012 at 11:33
  • 3
    Related question with good answer: stackoverflow.com/questions/607673/… Commented Feb 6, 2012 at 11:33
  • 1
    additionally 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 page Commented Feb 6, 2012 at 11:38
  • @DaveRandom Question edited... :) Commented Feb 6, 2012 at 11:38

2 Answers 2

3

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");
                            }
                        });
                     }
        });
Sign up to request clarification or add additional context in comments.

2 Comments

I dont know PHP but I give it a try. Create a file that is called myPHPscript.php and use: echo $_GET['selecteddate'];
The selecteddate variable will be passed thru QueryString ditio.net/2008/06/12/php-query-string
1

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'];
?>

More Information

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.