Forums

datepicker calendar to close after selecting

ataylor14 18 Oct, 2014
Dear all
I have 2 datepickers on my form. After selecting the dates the calendars remain opened on the form. I would like the calendar to close after the user selects a date. How can this be done?

I am thinking this situation might be caused by my using a script that is run upon selecting the dates and that somehow leaves the calendar open!?

I searched the forum but did not come across any similar question.

Thank you
Amelia
GreyHead 18 Oct, 2014
Hi Amelia,

Normally they do close - it sounds as though there may be a JavaScript error somewhere. Please post a link to the form so I can take a quick look.

Bob
ataylor14 20 Oct, 2014
I have two datepickers called: startdate and enddate. (there is also a hidden textbox no_night where I store the no nights selected).
In the parameters of each I invoke the function date_change
This will check that enddate is not before a day after startdate and if it is it will set endate = startdate+1.
the code is below. I have this suspicion that I am mixing mootools with jQuery a lot!

function date_change(){
        if   (total_nights() <1)
               {
               $('enddate').value = next_day();
               }
 $('no_nights').value = total_nights();
calculate_acc_cost();
}

function total_nights(){
$sd = $('startdate').value;
$sdDateParts= $sd.split("-");
$date1 = new Date($sdDateParts[2], $sdDateParts[1]-1, $sdDateParts[0]);
$ed = $('enddate').value;
$edDateParts= $ed.split("-");
$date2 = new Date($edDateParts[2], $edDateParts[1]-1, $edDateParts[0]);

$no_nights = dateDiffInDays($date1,$date2);
return $no_nights;
}

function next_day(){
$sd = $('startdate').value;
$sdDateParts= $sd.split("-");
$date1 = new Date($sdDateParts[2], $sdDateParts[1]-1, $sdDateParts[0]);
$newsd = parseInt($sdDateParts[0])+1+"-"+ $sdDateParts[1]+"-"+ $sdDateParts[2];
return $newsd;
}


function dateDiffInDays(a, b) {
var _MS_PER_DAY = 1000 * 60 * 60 * 24;
var utc1 = Date.UTC(a.getFullYear(), a.getMonth(), a.getDate());
var utc2 = Date.UTC(b.getFullYear(), b.getMonth(), b.getDate());

  return Math.floor((utc2 - utc1) / _MS_PER_DAY);
}
ataylor14 25 Oct, 2014
Answer
Hello
I would like to close this topic.
I solved the problem. Thank you.
Amelia
This topic is locked and no more replies can be posted.