Hi I made a calendar for your help.
However the if statement to compare from and to doesn't work correct.
the rule is
let's assume that From and To are selected.
then if From date is greater than To date, then To date has to be set on the date at 3 month later than the From date. but if not To date doesn't need to be changed.
I don't know why the if statement is not working.
and is there a debug tool? like debug() in PHP?
Please let me know.
Thank you
$(function () {
$("#from").datepicker({
maxDate: 0,
showButtonPanel : true,
closeText : 'Reset',
onClose: function () {
var today = new Date();
var from = $('#from').datepicker('getDate');
var from3 = from;
from3.setMonth(from3.getMonth() + 3);//3 month limit
var to = $('#to').datepicker('getDate');
var tdate = $("#from").datepicker("getDate");
if(to == ""){
$("#from").datepicker("option", "maxDate", today);
}
else{
if ($(window.event.srcElement).hasClass('ui-datepicker-close')) {
$.datepicker._clearDate(this);
$("#from").datepicker("option", "maxDate", today);
}
$("#from").datepicker("option", "maxDate", today);
tdate.setMonth(tdate.getMonth() + 3);
tdate = (tdate>today) ? today : tdate;
$("#to").datepicker("option", "maxDate", tdate);
if(from3 > to){
$('#to').datepicker('setDate', from3);
}
else if(from > to){
$('#to').datepicker('setDate', from);
}
}
}
});
$("#to").datepicker({
maxDate: 0,
showButtonPanel : true,
closeText : 'Reset',
onClose: function () {
var today = new Date();
var from = $('#from').datepicker('getDate');
var from3 = from;
from3.setMonth(from3.getMonth() + 3);//3 month limit
var to = $('#to').datepicker('getDate');
if(from == ""){
$('#from').datepicker('option', 'maxDate', today);
}
else{
if ($(window.event.srcElement).hasClass('ui-datepicker-close')) {
$.datepicker._clearDate(this);
$("#to").datepicker("option", "maxDate", today);
}
$("#to").datepicker("option", "maxDate", today);
if(from3 > to){
$('#from').datepicker('setDate', from3);
}
else if(from > to){
$('#to').datepicker('setDate', from3);
}
}
}
});
});
Aucun commentaire:
Enregistrer un commentaire