Categories | Question details Back To List | ||
Double Calendar - Syntax error when calling setTimeout I am having a problem with calling a setTimeout in my Double Calendar. See below.. The function seems to work fine when I call it on the left calendar but not on the right??? And onload will only load one of the functions??? var diia=""; var xmlHttp; function calchange(dvid,adr,str) { xmlHttp=GetXmlHttpObject(); if (xmlHttp==null) { alert ("Browser does not support HTTP Request"); return; } diia=dvid; var url=adr; var dii=dvid; var strw=new Date(str); str=strw.getDay(); url=url+"?q="+str; url=url+"&dii="+dii; url=url+"&sid="+Math.random(); xmlHttp.onreadystatechange=stateChanged; xmlHttp.open("GET",url,true); xmlHttp.send(null); return false; } function stateChanged() { if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") { document.getElementById(diia).innerHTML=xmlHttp.responseText; diia=null; } } function GetXmlHttpObject() { var xmlHttp=null; try { // Firefox, Opera 8.0+, Safari xmlHttp=new XMLHttpRequest(); } catch (e) { //Internet Explorer try { xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); } } return xmlHttp; } window.dhx_globalImgPath="./codebase/imgs/"; window.onload = function () { var StartBookingDate=new Date(); var NextBookingDate=new Date(); NextBookingDate.setDate(NextBookingDate.getDate()+5); var PrevBookingDate=new Date(); PrevBookingDate.setDate(PrevBookingDate.getDate()+28); var EndBookingDate=new Date(); EndBookingDate.setDate(StartBookingDate.getDate()+29); var StartBookingYear=StartBookingDate.getYear(); var EndBookingYear=(EndBookingDate.getYear()+1); mDCal = new dhtmlxDblCalendarObject('dhtmlxDblCalendar', false, {isMonthEditable: true, isYearEditable: true}); mDCal.setYearsRange(StartBookingYear,EndBookingYear); mDCal.setDateFormat("%d/%m/%Y"); mDCal.leftCalendar.setSensitive(new Date(StartBookingDate),null); mDCal.rightCalendar.setSensitive(new Date(StartBookingDate),null); mDCal.leftCalendar.setInsensitiveDates("12-25,12-26,12-27,12-28"); mDCal.rightCalendar.setInsensitiveDates("12-25,12-26,12-27,12-28"); mDCal.setHolidays(['12-25','12-26','12-27','12-28']); mDCal.setDate(document.getElementById('depart').value,document.getElementById('return').value); mDCal.draw(); mDCal.setOnClickHandler(function(date,self,type){ if (type=="right") document.getElementById("return").value = mDCal.rightCalendar.getFormatedDate(null,date); window.setTimeout('calchange("ReturnTime","returnchange1a.php",mDCal.rightCalendar.getDate())',1); //doesn't work ??? Syntax error else document.getElementById("depart").value = mDCal.leftCalendar.getFormatedDate(null,date); window.setTimeout('calchange("CollectionTime","departchange1a.php",mDCal.leftCalendar.getDate())',1); // works great window.setTimeout(function(){ var time2 = Date.parse(mDCal.rightCalendar.getDate()) - Date.parse(mDCal.leftCalendar.getDate()); document.getElementById('daycount').value=(Math.floor(time2/(1000*60*60*24))); },1); }) // set date difference at page load var time1 = Date.parse(mDCal.rightCalendar.getDate()) - Date.parse(mDCal.leftCalendar.getDate()); //get difference document.getElementById("daycount").value = Math.floor(time1 / (1000*60*60*24)); //convert it to days // set times according to day of date at page load window.setTimeout('calchange("ReturnTime","returnchange1a.php",mDCal.rightCalendar.getDate())',1); // doesn't work (unless line below removed) window.setTimeout('calchange("CollectionTime","departchange1a.php",mDCal.leftCalendar.getDate())',1); // works great } Answer posted by Alex (support) on Apr 15, 2009 09:34 It seems that the issue isn't related to calendar component. If you're sure that rightCalendar.getDate() or leftCalendar.getDate() doesn't return the date in some cases, please, provide the sample which demonstrates it. Answer posted by David Keenan on Apr 15, 2009 13:58 You are right, the issue was with my javascript, I needed to bracket my if statement better. Its working now, and I have to say I really love the double calendar. Thanks for the point in the right direction.
|