开发者

jQuery datepicker - defaultDate (dynamically) from another datepicker

I have two datepickers at the moment, one for a start date, and another for an end date.

When you select the first date, I'd like the default value of the second datepicker to be set to the same date. If I use the setDate it works and sets the value just fine, but the default value won't change - if I set the defaultDate when the datepicker is loaded, it works, but if I try to set it on the fly it doesn't.

Here's my code:

if($('#startDate').val().length == 10 && $("#endDate").val().length != 10) {
    $("#endDate").datepicker("defaultDate", $("#startDate").datepicker("getDate"));
}

(edit) for clarification, I don't want to set the date - the user needs to do that, but I'd like the datepicker to go straight to the same date as the start date, t开发者_JS百科o save them having to trawl through numerous pages.

Here's the (kinda) working code: http://jsfiddle.net/c8H5y/

Any suggestions would be very welcome, thank you!


This should do it:

$("#dep_date").datepicker({
    dateFormat: 'dd/mm/yy',
    onSelect: function(dateText, inst) {
        var date = $.datepicker.parseDate('dd/mm/yy', dateText);
        var $ret_date = $("#ret_date");
        $ret_date.datepicker("option", "defaultDate", date);
    }
});

$("#ret_date").datepicker({
    dateFormat: 'dd/mm/yy',
});

jsFiddle

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜