Seth
Seth

Reputation: 123

jQuery datepicker onSelect Pass Variable to Update Selection List

I have the following code thus far

<script>      
$(function() {
    $('#datepicker').datepicker( {
        dateFormat: 'yy-mm-dd',
        onSelect: function(date) {
            $("#eventoutput").empty()
            $.ajax({        
            url: 'getevents.php', data: "pickdate=2014-04-06", dataType: 'json',  success: function(rows)
            {
                for (var i in rows)
                    {
                      var row = rows[i];          

                      var eventtitle = row[0];
                      $('#eventoutput').append("<option value=\""+eventtitle+"\">"+eventtitle+"</option>");
                    }
                }
            });
        }
    });
});
</script>

Where the date is currently hardcoded (2014-04-06), I would like to pass the value/date selected in the format (yyyy-mm-dd).

I'm not sure of the appropriate syntax. Thanks much.

Upvotes: 0

Views: 822

Answers (1)

Sam Battat
Sam Battat

Reputation: 5745

use that date variable passed in the onSelect function

onSelect: function(date) {
            $("#eventoutput").empty()
            $.ajax({        
            url: 'getevents.php', data: "pickdate="+date, dataType: 'json',  success: function(rows)
                {
                    ......
                    ......
                }
            });
}

Working example:

http://jsfiddle.net/Fa8Xx/1514/

Upvotes: 1

Related Questions