如何在php中回显/测试jQuery变量?

As the title says, how can i test/show my jQuery variable in php? I have created a datepicker and on the click of a specific date, that date needs to be stored into a variable so i can use it later on (like for example to show your date of birth).

The code of the datepicker and the Onselect is:

$(document).ready(function(){
    $("#datepicker").datepicker({
        onSelect: function(dateText, inst) {
            alert(dateText);
            document.getElementById('thedate').value=dateText;
        },
        showOn: "button",
        buttonImage: "/debasis/hoofdstuk03/img/calendar.png",
        buttonText: "Open de kalender",
        buttonImageOnly: true,
        inline: true,  
        showOtherMonths: true,  
        dayNamesMin: ['Ma', 'Di', 'Wo', 'Do', 'Vr', 'Za','Zo'],  
        monthNames: ['Januari', 'Februari', 'Maart', 'April', 'Mei', 'Juni',
            'Juli', 'Augustus', 'September', 'Oktober', 'November', 'December'],

    });
});

The HTML to show the datepicker is:

<div type="text" id="datepicker"></div>
   <form method=post>
       <input type='text' id='thedate' name='thedate' />
   </form>

If im right, but correct me if i am wrong, when i click a date on the calendar, that date is being POST and the Jquery variable 'thedate' will be set in $_POST['thedate'] is this correct?

However to be sure i got the chosen date in my $_POST (so i can use this variable to store it in my databse) i wanted to test it with an echo. So in the same file i created this to test it:

<?php print_r($_POST); ?>

Though this little line doesnt return anything? Anyone knows how i can test/show 'thedate' variable (the chosen date)? So i know the chosen date is stored in a variable. I would like to get it returned in a PHP variable so i can store it in my databse.. Though if there are other ways to do it i am open for those solutions as well. :)

nope; it doesn't work like that. It's not enough to just change input value. You need to actually submit the form - which means comunicating with php which is BACK-END, to be able to show it using PHP.

the easiest way would be to submit the form in onSelect method:

HTML:

JS:

    $("#datepicker").datepicker({
            onSelect: function(dateText, inst) {
                alert(dateText);
                document.getElementById('thedate').value=dateText;
                document.getElementById("myForm").submit();
            },
    ...

and then print it out usign PHP:

<?php print_r($_POST); ?>

AJAX post it to an external php file. $_SESSION the var in that file and use it wherever else.