JQuery Datepicker - Using selected date

JQuery Datepicker - Using selected date

Hello,

I'm new to both JS and JQuery. I added a JQuery datepicker to a website but now I am unable to figure out how to access the value clicked? I'm using the following code:

<script type="text/javascript">
    $(document).ready(function(){
    $("#datepicker").datepicker({
    dateFormat: 'yy-mm-dd',
    onSelect: function(dateText, inst){
    $("#result").text("You selected " + dateText);
    }
    });
    });
    </script>

Then the html:
<div type="text" id="datepicker" style="font-size:65%;"></div>
                        <div style="font-size:100%;"
                        id="result"></div>

Which creates a datepicker object and shows the date selected below the calendar when a date is clicked.

I need to access the value clicked to use in a php script so my question is.

1. How do I assign the date selected to a session variable?
2. can I do it from outside the script?
3. Where can I find the documentation to do it from inside the script? And what type of function would be the best way to do it?

thanks