I'm setting the start date of an event using jQuery UI Datepicker. Now I need to retrieve the selected date. I'm trying to use $('#startDate').datepicker('getDate')
, but this returns NULL.
Using FirBug, I see that the input value is nothing :-
<input type="text" name="startDate" value="" id="startDate" class="hasDatepicker">
So how can I retrieve the selected date?
PS. : I found an old thread regarding he exact same issue.
http://old.nabble.com/ui.datepicker-trouble-td17846951s27240.htmlBut the solution here does not work for me. I just get an error message开发者_开发技巧 :-
uncaught exception: Missing instance data for this datepicker
UPDATE :
I'm able to retrieve the selected date by using this code:
var arr = $('#newEvent').serializeArray();
alert(arr[2].value);
But this is by far the best way....b/w any other suggestions is appreciated.
You can use a callback to let it push it to your data :)
$('#startDate').datepicker({
onChangeMonthYear: function(year, month, inst) { ... }
});
Easy to solve, change your code to:
$('.date').live('focus', function(){
$(this).datepicker({
changeMonth: true,
changeYear: true,
yearRange: '1930:'+(new Date).getFullYear()
});
});
精彩评论