javascript - How to disable dates in jQuery datepicker? -
i have 2 datepicker filling checkin text box , checkout text box. have enable checkin+13 days in checkout datepicker. tried is-
$("#chkin").datepicker({ dateformat: 'dd/mm/yy', mindate: '+0', onclose: function (datetext, inst) { if ($("#ctl00_contentplaceholder1_hdndateformat").val() == "dd/mm/yy") { var parts = datetext.split("/"); var cin = new date(number(parts[2]), number(parts[1]) - 1, number(parts[0])); } else { var cin = new date(datetext); } var cout = new date(cin.getfullyear(), cin.getmonth(), cin.getdate()+1); $("#chkout").datepicker('option', 'mindate', cout).datepicker('show'); showdays(); } }); var cin = new date($("#chkin").val()); var cout = new date(cin.getfullyear(), cin.getmonth(), cin.getdate()+1); var maxout= new date(cin.getdate()+13); $("#chkout").datepicker({ dateformat: 'dd/mm/yy', mindate: cout, maxdate: maxout, onselect: showdays }); where went wrong?
i able make work using following code. note had deviate bit pasted code since did not have access showdays function. anyway issue in code while constructing maxout date object, using var maxout = new date(cin.getdate()+13), construct date object using cin.getdate()+13 given year. setting maxdate option on checkout datepicker in onclose function. see date constructor arguments @ http://www.w3schools.com/js/js_obj_date.asp
$(function() { $("#chkin").datepicker({ dateformat: 'dd/mm/yy', mindate: '+0', onclose: function (datetext, inst) { var cin = $(this).datepicker( "getdate" ); // returns date object, or null nothing selected. if(cin != null && cin != 'invalid date'){ // check valid date object, can done in better way. var cout = new date(cin.getfullyear(), cin.getmonth(), cin.getdate()+1); var maxout = new date(cin.getfullyear(), cin.getmonth(), cin.getdate()+13); $("#chkout").datepicker('option', 'mindate', cout) .datepicker( "option", "maxdate", maxout ) .datepicker('show'); } } }); var cin = $("#chkin").datepicker( "getdate" ); //new date($("#chkin").val()); if(cin != null && cin != 'invalid date'){ // check valid date object, can done in better way. var cout = new date(cin.getfullyear(), cin.getmonth(), cin.getdate()+1); var maxout= new date(cin.getfullyear(), cin.getmonth(), cin.getdate()+13); $("#chkout").datepicker({ dateformat: 'dd/mm/yy', mindate: cout, maxdate: maxout}); }else{ $("#chkout").datepicker({ dateformat: 'dd/mm/yy'}); } });
Comments
Post a Comment