开发者

How do I get selected date set by jQuery UI Datepicker

开发者 https://www.devze.com 2023-01-03 18:39 出处:网络
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.

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.html

But 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()
    });
});
0

精彩评论

暂无评论...
验证码 换一张
取 消