2
Contributors
4
Replies
5
Views
6 Years
Discussion Span
Last Post by mrlol
1

It doesn't behave as the documentation says it should.

Both sample date formats "yyyyMMdd" and "yyyyMMMdd" give "undefined".

Try adding the following lines to function FormatDate :

else if (this.Format.toUpperCase()=="YYYYMMDD")
		return (this.Year+DateSeparator+(this.Month+1)+DateSeparator+pDate);

Airshow

Edited by Airshow: n/a

0

thanks for your reply sir,

but i would like to reconfirm with u..
after i add the following codes above, everything was fine.. i pick any date and the date format inserted correctly but there's nothing happen (no calendar pop-up) when i clicked the calendar to re-pick the date.

pls advice. TQ

1

I think the best advice would be to find a better datepicker but if you want to stick with that one, then try replacing function NewCal(){...} with :

if(!String.prototype.trim) {
	String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g, ''); };
}

function NewCal(pCtrl,pFormat,pShowTime,pTimeMode) {
	Cal = new Calendar(dtToday);
	if ((pShowTime!==null) && pShowTime) {
		Cal.ShowTime=true;
		if ((pTimeMode!==null) &&((parseInt(pTimeMode,10)===12)||(parseInt(pTimeMode,10)===24))) {
			TimeMode=pTimeMode;
		}
	}
	if (pCtrl!==null) { Cal.Ctrl=pCtrl; }
	if (pFormat!==null) { Cal.Format=pFormat.toUpperCase(); }
	
	exDateTime=document.getElementById(pCtrl).value.trim();

	if (exDateTime!=="") {//Parse Date String
		var parserArray = exDateTime.split(/\s+/g);
		var exDateArray = (parserArray[0]) ? parserArray[0].split(DateSeparator) : '';
		var exTimeArray = (parserArray[1]) ? parserArray[1].split(':') : '';
		var strMonth;
		var strDate;
		var strYear;
		var intMonth;
		var YearPattern;
		//extract date, month and year
		switch (Cal.Format.toUpperCase()) {
			case "DDMMYYYY":
			case "DDMMMYYYY":
				strDate=exDateArray[0];
				strMonth=exDateArray[1];
				strYear=exDateArray[2];
			break;
			case "MMDDYYYY":
			case "MMMDDYYYY":
				strDate=exDateArray[1];
				strMonth=exDateArray[0];
				strYear=exDateArray[2];
			break;
			case "YYYYMMDD":
			case "YYYYMMMDD":
				strDate=exDateArray[2];
				strMonth=exDateArray[1];
				strYear=exDateArray[0];
			break;
		} 
		//... month
		if (isNaN(strMonth)) { intMonth=Cal.GetMonthIndex(strMonth); }
		else { intMonth=parseInt(strMonth,10)-1; }
		if ((parseInt(intMonth,10)>=0) && (parseInt(intMonth,10)<12))  { Cal.Month=intMonth; }
		//... date
		if ((parseInt(strDate,10)<=Cal.GetMonDays()) && (parseInt(strDate,10)>=1)) { Cal.Date=strDate; }
		//... year
		YearPattern=/^\d{4}$/;
		if (YearPattern.test(strYear)) { Cal.Year=parseInt(strYear,10); }
		//parse time
		if (Cal.ShowTime) {
			Cal.SetHour(exTimeArray[0]);
			Cal.SetMinute(exTimeArray[1]);
			Cal.SetSecond(exTimeArray[2]);
		}
	}
	winCal=window.open("","DateTimePicker","toolbar=0,status=0,menubar=0,fullscreen=no,width=195,height=245,resizable=0,top="+cnTop+",left="+cnLeft);
	docCal=winCal.document;
	RenderCal();
}

and replacing function FormatDate(){...} with:

function FormatDate(pDate) {
	var rtnStr;
	switch(this.Format.toUpperCase()) {
		case "DDMMYYYY":  rtnStr = [pDate, this.Month+1, this.Year].join(DateSeparator); break;
		case "DDMMMYYYY": rtnStr = [pDate, this.GetMonthName(false), this.Year].join(DateSeparator); break;
		case "MMDDYYYY":  rtnStr = [this.Month+1, pDate, this.Year].join(DateSeparator); break;
		case "YYYYMMDD":  rtnStr = [this.Year, this.Month+1, pDate].join(DateSeparator); break;
		case "MMMDDYYYY": rtnStr = [this.GetMonthName(false), pDate, this.Year].join(DateSeparator); break;
		case "MMDDYYYY":  rtnStr = [this.Month+1, pDate, this.Year].join(DateSeparator); break;
	}
	return rtnStr;
}

Airshow

Votes + Comments
very helpful. thank you very much!
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.