Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to select date future in datepicker jquery

i'm using datePicker in this way:

$("#dataStart").datepicker({
beforeShow: function () { $('#ui-datepicker-div').css('z-index',9999); },
dateFormat: 'mm/dd/yy'});
$("#dataEnd").datepicker({
beforeShow: function () { $('#ui-datepicker-div').css('z-index',9999); },
dateFormat: 'mm/dd/yy'});

I want to force select a date in future and not in the past, is there a possibility to do it? if so, is possible to change in a dynamic way for the second datepicker, so if user select a date, in the second field he has to select a date next to the first selected. i hope i ask as well my question :) Thanks all!

like image 595
Jayyrus Avatar asked Dec 10 '22 02:12

Jayyrus


1 Answers

minDate:1 should only allow dates tomorrow and onward. Then add an onselect to restrict dataEnd:

$("#dataStart").datepicker({
    minDate: 1,
    onSelect: function(theDate) {
        $("#dataEnd").datepicker('option', 'minDate', new Date(theDate));
    },
    beforeShow: function() {
        $('#ui-datepicker-div').css('z-index', 9999);
    },
    dateFormat: 'mm/dd/yy'
});

Reference: http://blog.alagad.com/2009/04/20/playing-with-jquery-datepicker/

Example: http://jsfiddle.net/jtbowden/F39kt/

like image 177
Jeff B Avatar answered Dec 31 '22 01:12

Jeff B