I have JavaScript code to dispaly two month calendar days at a time, but i have a problem both month that disaplay at a time have same days (for example May and June has same days, June and July have same days etc.) Instate of correct days. Here is my code from 3 files.
************************************************** ************************************* calendr.js file: - isIE = (document.all ? true : false);
-
isDOM = (document.getElementById ? true : false);
-
-
// Initializing arrays
-
var months = new Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul",
-
"Aug", "Sep", "Oct", "Nov", "Dec", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul",
-
"Aug", "Sep", "Oct", "Nov", "Dec");
-
var daysInMonth = new Array(31, 28, 31, 30, 31, 30, 31, 31,
-
30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31,
-
30, 31, 30, 31);
-
-
var displayMonth = new Date().getMonth();
-
var displayYear = new Date().getFullYear();
-
var displayDivName;
-
var displayElement;
-
-
function getDays(month, year) {
-
// Check for leap year when February is selected
-
if (1 == month)
-
return ((0 == year % 4) && (0 != (year % 100))) ||
-
(0 == year % 400) ? 29 : 28;
-
else
-
return daysInMonth[month];
-
-
}
-
-
function getToday() {
-
// Create today's date.
-
this.now = new Date();
-
this.year = this.now.getFullYear();
-
this.month = this.now.getMonth();
-
this.day = this.now.getDate();
-
}
-
-
// Start calendar with today
-
today = new getToday();
-
-
function newCalendar(eltName,attachedElement) {
-
if (attachedElement) {
-
if (displayDivName && displayDivName != eltName) hideElement(displayDivName);
-
displayElement = attachedElement;
-
}
-
-
displayDivName = eltName;
-
today = new getToday();
-
var parseYear = parseInt(displayYear + '');
-
var newCal = new Date(parseYear,displayMonth,1);
-
var day = -1;
-
var startDayOfWeek = newCal.getDay();
-
-
if ((today.year == newCal.getFullYear()) &&
-
(today.month == newCal.getMonth()))
-
{
-
day = today.day;
-
}
-
-
var intDaysInMonth =
-
getDays(newCal.getMonth(), newCal.getFullYear());
-
-
-
var daysGrid = makeDaysGrid(startDayOfWeek,day,intDaysInMonth,newCal,eltName)
-
-
if (isIE) {
-
var elt = document.all[eltName];
-
elt.innerHTML = daysGrid;
-
} else if (isDOM) {
-
var elt = document.getElementById(eltName);
-
elt.innerHTML = daysGrid;
-
} else {
-
var elt = document.layers[eltName].document;
-
elt.open();
-
elt.write(daysGrid);
-
elt.close();
-
}
-
}
-
-
function incMonth(delta,eltName) {
-
displayMonth = displayMonth+delta;
-
if (displayMonth >= 12) {
-
displayMonth = 0;
-
incYear(1,eltName);
-
} else if (displayMonth <= -1) {
-
displayMonth = 11;
-
incYear(-1,eltName);
-
} else {
-
newCalendar(eltName);
-
}
-
}
-
-
function incYear(delta,eltName) {
-
displayYear = parseInt(displayYear + '') + delta;
-
newCalendar(eltName);
-
}
-
-
function makeDaysGrid(startDay,day,intDaysInMonth,newCal,eltName) {
-
var daysGrid;
-
var month = newCal.getMonth();
-
var year = newCal.getFullYear();
-
var isThisYear = (year == new Date().getFullYear());
-
var isThisMonth = (day > -1)
-
-
daysGrid = '<table border=1 cellspacing=0 cellpadding=2><tr><td bgcolor=#ffffff nowrap>';
-
daysGrid += '<font face="courier new, courier" size=2>';
-
daysGrid += ' ';
-
-
if (isThisMonth) {daysGrid += ' ';}
-
else
-
{daysGrid += '<a href="javascript:incMonth(-1,\'' + eltName + '\')"><img src="https://images.hertz.com/misc/arrow_lft.gif" border="0" valign="bottom"></a>';}
-
-
daysGrid += '<b>';
-
if (isThisMonth) { daysGrid += '<font color=#ffcc00>' + months[month] + '</font>'; }
-
else { daysGrid += months[month]; }
-
daysGrid += '</b>';
-
-
daysGrid += ' ';
-
daysGrid += months[month+1];
-
-
daysGrid += '<a href="javascript:incMonth(1,\'' + eltName + '\')"><img src="https://images.hertz.com/misc/arrow_rgt.gif" border="0" valign="bottom"></a>';
-
daysGrid += ' ';
-
-
daysGrid += ' <a href="javascript:hideElement(\'' + eltName + '\')">x</a><br>';
-
daysGrid += '<b> S M T W T F S </b> <br>';
-
-
-
var dayOfMonthOfFirstSunday = (7 - startDay + 1);
-
for (var intWeek = 0; intWeek < 6; intWeek++) {
-
var dayOfMonth;
-
for (var intDay = 0; intDay < 7; intDay++) {
-
dayOfMonth = (intWeek * 7) + intDay + dayOfMonthOfFirstSunday - 7;
-
-
if (dayOfMonth <= 0) {
-
daysGrid += " ";
-
} else if (dayOfMonth <= intDaysInMonth) {
-
var color = "#3366AA";
-
if (day > 0 && day == dayOfMonth) color="#ffcc00";
-
-
daysGrid += '<a href="javascript:setDay(';
-
daysGrid += dayOfMonth + ',\'' + eltName + '\')" '
-
daysGrid += 'style="color:' + color + '">';
-
var dayString = dayOfMonth + "</a> ";
-
if (dayString.length == 6) dayString = '0' + dayString;
-
daysGrid += dayString;
-
}
-
}
-
-
-
if (dayOfMonth < intDaysInMonth) daysGrid += "<br> ";
-
}
-
-
-
-
daysGrid += '<br><br>' + months[month+1] + '<br>';
-
-
daysGrid += '<br><b> S M T W T F S </b><br> ';
-
-
-
var dayOfMonthOfFirstSunday = (7 - startDay + 1);
-
for (var intWeek = 0; intWeek < 6; intWeek++) {
-
var dayOfMonth;
-
for (var intDay = 0; intDay < 7; intDay++) {
-
dayOfMonth = (intWeek * 7) + intDay + dayOfMonthOfFirstSunday - 7;
-
-
if (dayOfMonth <= 0) {
-
daysGrid += " ";
-
} else if (dayOfMonth <= intDaysInMonth) {
-
var color = "#3366AA";
-
if (day > 0 && day == dayOfMonth) color="#ffcc00";
-
-
daysGrid += '<a href="javascript:setDay(';
-
daysGrid += dayOfMonth + ',\'' + eltName + '\')" '
-
daysGrid += 'style="color:' + color + '">';
-
var dayString = dayOfMonth + "</a> ";
-
if (dayString.length == 6) dayString = '0' + dayString;
-
daysGrid += dayString;
-
}
-
}
-
-
-
if (dayOfMonth < intDaysInMonth) daysGrid += "<br> ";
-
}
-
-
-
-
return daysGrid + "</td></tr></table>";
-
}
-
-
-
function setDay(day,eltName) {
-
displayElement.value = (displayMonth + 1) + "/" + day + "/" + displayYear;
-
hideElement(eltName);
-
}
-
************************************************** ********************************** leisure_cal.js file: - isIE = (document.all ? true : false);
-
isDOM = (document.getElementById ? true : false);
-
function getAbsX(elt) { return (elt.x) ? elt.x : getAbsPos(elt,"Left"); }
-
function getAbsY(elt) { return (elt.y) ? elt.y : getAbsPos(elt,"Top"); }
-
-
function getAbsPos(elt,which) {
-
iPos = 0;
-
while (elt != null) {
-
iPos += elt["offset" + which];
-
elt = elt.offsetParent;
-
}
-
return iPos;
-
}
-
-
function getDivStyle(divname) {
-
var style;
-
if (isDOM) { style = document.getElementById(divname).style; }
-
else { style = isIE ? document.all[divname].style
-
: document.layers[divname]; }
-
return style;
-
}
-
-
function hideElement(divname) {
-
getDivStyle(divname).visibility = 'hidden';
-
}
-
-
function moveBy(elt,deltaX,deltaY) {
-
elt.left = parseInt(elt.left) + deltaX;
-
elt.top = parseInt(elt.top) + deltaY;
-
}
-
-
function toggleVisible(divname) {
-
divstyle = getDivStyle(divname);
-
if (divstyle.visibility == 'visible' || divstyle.visibility == 'show') {
-
divstyle.visibility = 'hidden';
-
} else {
-
fixPosition(divname);
-
divstyle.visibility = 'visible';
-
}
-
}
-
-
function setPosition(elt,positionername,isPlacedUnder) {
-
var positioner;
-
if (isIE) {
-
positioner = document.all[positionername];
-
} else {
-
if (isDOM) {
-
positioner = document.getElementById(positionername);
-
} else {
-
positioner = document.images[positionername];
-
}
-
}
-
elt.left = getAbsX(positioner);
-
elt.top = getAbsY(positioner) + (isPlacedUnder ? positioner.height : 0);
-
}
-
************************************************** ********************************* calendar.html file:
[HTML]<html>
<head><title>DHTML Calendar</title>
<script language="JavaScript1.2" src="leisure_cal.js"></script>
<script language="JavaScript1.2" src="calendar.js"></script>
<script language="JavaScript1.2">
<!--
function fixPosition(divname) {
divstyle = getDivStyle(divname);
positionerImgName = divname + 'Pos';
isPlacedUnder = false;
if (isPlacedUnder) {
setPosition(divstyle,positionerImgName,true);
} else {
setPosition(divstyle,positionerImgName)
}
}
function toggleDatePicker(eltName,formElt) {
var x = formElt.indexOf('.');
var formName = formElt.substring(0,x);
var formEltName = formElt.substring(x+1);
newCalendar(eltName,document.forms[formName].elements[formEltName]);
toggleVisible(eltName);
}
function fixPositions()
{
fixPosition('daysOfMonth');
fixPosition('daysOfMonth2');
}
// -->
</script>
</head>
<body onresize="fixPositions()">
<form name="date">
<center>
<table border=0>
<tr>
<td>Pick-Up Date: </td>
<td><INPUT name=ret size="10" onmouseup="toggleDatePicker('daysOfMonth','date.re t')" id=daysOfMonthPos name=daysOfMonthPos align=absmiddle><div id="daysOfMonth" style="position:absolute;"></div></td>
</tr>
<tr>
<td>Return Date: </td>
<td><INPUT name=ret2 size="10" onmouseup="toggleDatePicker('daysOfMonth2','date.r et2')" id=daysOfMonth2Pos name=daysOfMonth2Pos align=absmiddle><div id="daysOfMonth2" style="position:absolute;"></div></td>
</tr>
</table>
</center>
</form>
<SCRIPT language=JavaScript1.2>
function Cancel() {
hideElement("daysOfMonth");
}
</SCRIPT>
<script language="JavaScript1.2">
<!--
hideElement('daysOfMonth');
hideElement('daysOfMonth2');
//-->
</script>[/HTML]
7 3763
I have JavaScript code to dispaly two month calendar
days at a time, but i have a problem. Both month that
disaplay at a time have same days (for example May and
June has same days, June and July have same days etc.)
When May and June days dispaly, May has correct days
but June has incorrect days becuase it has same as May
etc.
Here is my code from 3 files. Save this 1 html and 2 js files on your pc so that you can
see problem on your browser screen.
************************************************** ************************************* calendr.js file: - isIE = (document.all ? true : false);
-
isDOM = (document.getElementById ? true : false);
-
-
// Initializing arrays
-
var months = new Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul",
-
"Aug", "Sep", "Oct", "Nov", "Dec", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul",
-
"Aug", "Sep", "Oct", "Nov", "Dec");
-
var daysInMonth = new Array(31, 28, 31, 30, 31, 30, 31, 31,
-
30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31,
-
30, 31, 30, 31);
-
-
var displayMonth = new Date().getMonth();
-
var displayYear = new Date().getFullYear();
-
var displayDivName;
-
var displayElement;
-
-
function getDays(month, year) {
-
// Check for leap year when February is selected
-
if (1 == month)
-
return ((0 == year % 4) && (0 != (year % 100))) ||
-
(0 == year % 400) ? 29 : 28;
-
else
-
return daysInMonth[month];
-
-
}
-
-
function getToday() {
-
// Create today's date.
-
this.now = new Date();
-
this.year = this.now.getFullYear();
-
this.month = this.now.getMonth();
-
this.day = this.now.getDate();
-
}
-
-
// Start calendar with today
-
today = new getToday();
-
-
function newCalendar(eltName,attachedElement) {
-
if (attachedElement) {
-
if (displayDivName && displayDivName != eltName) hideElement(displayDivName);
-
displayElement = attachedElement;
-
}
-
-
displayDivName = eltName;
-
today = new getToday();
-
var parseYear = parseInt(displayYear + '');
-
var newCal = new Date(parseYear,displayMonth,1);
-
var day = -1;
-
var startDayOfWeek = newCal.getDay();
-
-
if ((today.year == newCal.getFullYear()) &&
-
(today.month == newCal.getMonth()))
-
{
-
day = today.day;
-
}
-
-
var intDaysInMonth =
-
getDays(newCal.getMonth(), newCal.getFullYear());
-
-
-
var daysGrid = makeDaysGrid(startDayOfWeek,day,intDaysInMonth,new Cal,eltName)
-
-
if (isIE) {
-
var elt = document.all[eltName];
-
elt.innerHTML = daysGrid;
-
} else if (isDOM) {
-
var elt = document.getElementById(eltName);
-
elt.innerHTML = daysGrid;
-
} else {
-
var elt = document.layers[eltName].document;
-
elt.open();
-
elt.write(daysGrid);
-
elt.close();
-
}
-
}
-
-
function incMonth(delta,eltName) {
-
displayMonth = displayMonth+delta;
-
if (displayMonth >= 12) {
-
displayMonth = 0;
-
incYear(1,eltName);
-
} else if (displayMonth <= -1) {
-
displayMonth = 11;
-
incYear(-1,eltName);
-
} else {
-
newCalendar(eltName);
-
}
-
}
-
-
function incYear(delta,eltName) {
-
displayYear = parseInt(displayYear + '') + delta;
-
newCalendar(eltName);
-
}
-
-
function makeDaysGrid(startDay,day,intDaysInMonth,newCal,el tName) {
-
var daysGrid;
-
var month = newCal.getMonth();
-
var year = newCal.getFullYear();
-
var isThisYear = (year == new Date().getFullYear());
-
var isThisMonth = (day > -1)
-
-
daysGrid = '<table border=1 cellspacing=0 cellpadding=2><tr><td bgcolor=#ffffff nowrap>';
-
daysGrid += '<font face="courier new, courier" size=2>';
-
daysGrid += ' ';
-
-
if (isThisMonth) {daysGrid += ' ';}
-
else
-
{daysGrid += '<a href="javascript:incMonth(-1,\'' + eltName + '\')"><img src="https://images.hertz.com/misc/arrow_lft.gif" border="0" valign="bottom"></a>';}
-
-
daysGrid += '<b>';
-
if (isThisMonth) { daysGrid += '<font color=#ffcc00>' + months[month] + '</font>'; }
-
else { daysGrid += months[month]; }
-
daysGrid += '</b>';
-
-
daysGrid += ' ';
-
daysGrid += months[month+1];
-
-
daysGrid += '<a href="javascript:incMonth(1,\'' + eltName + '\')"><img src="https://images.hertz.com/misc/arrow_rgt.gif" border="0" valign="bottom"></a>';
-
daysGrid += ' ';
-
-
daysGrid += ' <a href="javascript:hideElement(\'' + eltName + '\')">x</a><br>';
-
daysGrid += '<b> S M T W T F S </b> <br>';
-
-
-
var dayOfMonthOfFirstSunday = (7 - startDay + 1);
-
for (var intWeek = 0; intWeek < 6; intWeek++) {
-
var dayOfMonth;
-
for (var intDay = 0; intDay < 7; intDay++) {
-
dayOfMonth = (intWeek * 7) + intDay + dayOfMonthOfFirstSunday - 7;
-
-
if (dayOfMonth <= 0) {
-
daysGrid += " ";
-
} else if (dayOfMonth <= intDaysInMonth) {
-
var color = "#3366AA";
-
if (day > 0 && day == dayOfMonth) color="#ffcc00";
-
-
daysGrid += '<a href="javascript:setDay(';
-
daysGrid += dayOfMonth + ',\'' + eltName + '\')" '
-
daysGrid += 'style="color:' + color + '">';
-
var dayString = dayOfMonth + "</a> ";
-
if (dayString.length == 6) dayString = '0' + dayString;
-
daysGrid += dayString;
-
}
-
}
-
-
-
if (dayOfMonth < intDaysInMonth) daysGrid += "<br> ";
-
}
-
-
-
-
daysGrid += '<br><br>' + months[month+1] + '<br>';
-
-
daysGrid += '<br><b> S M T W T F S </b><br> ';
-
-
-
var dayOfMonthOfFirstSunday = (7 - startDay + 1);
-
for (var intWeek = 0; intWeek < 6; intWeek++) {
-
var dayOfMonth;
-
for (var intDay = 0; intDay < 7; intDay++) {
-
dayOfMonth = (intWeek * 7) + intDay + dayOfMonthOfFirstSunday - 7;
-
-
if (dayOfMonth <= 0) {
-
daysGrid += " ";
-
} else if (dayOfMonth <= intDaysInMonth) {
-
var color = "#3366AA";
-
if (day > 0 && day == dayOfMonth) color="#ffcc00";
-
-
daysGrid += '<a href="javascript:setDay(';
-
daysGrid += dayOfMonth + ',\'' + eltName + '\')" '
-
daysGrid += 'style="color:' + color + '">';
-
var dayString = dayOfMonth + "</a> ";
-
if (dayString.length == 6) dayString = '0' + dayString;
-
daysGrid += dayString;
-
}
-
}
-
-
-
if (dayOfMonth < intDaysInMonth) daysGrid += "<br> ";
-
}
-
-
-
-
return daysGrid + "</td></tr></table>";
-
}
-
-
-
function setDay(day,eltName) {
-
displayElement.value = (displayMonth + 1) + "/" + day + "/" + displayYear;
-
hideElement(eltName);
-
}
-
************************************************** ********************************** leisure_cal.js file: - isIE = (document.all ? true : false);
-
isDOM = (document.getElementById ? true : false);
-
function getAbsX(elt) { return (elt.x) ? elt.x : getAbsPos(elt,"Left"); }
-
function getAbsY(elt) { return (elt.y) ? elt.y : getAbsPos(elt,"Top"); }
-
-
function getAbsPos(elt,which) {
-
iPos = 0;
-
while (elt != null) {
-
iPos += elt["offset" + which];
-
elt = elt.offsetParent;
-
}
-
return iPos;
-
}
-
-
function getDivStyle(divname) {
-
var style;
-
if (isDOM) { style = document.getElementById(divname).style; }
-
else { style = isIE ? document.all[divname].style
-
: document.layers[divname]; }
-
return style;
-
}
-
-
function hideElement(divname) {
-
getDivStyle(divname).visibility = 'hidden';
-
}
-
-
function moveBy(elt,deltaX,deltaY) {
-
elt.left = parseInt(elt.left) + deltaX;
-
elt.top = parseInt(elt.top) + deltaY;
-
}
-
-
function toggleVisible(divname) {
-
divstyle = getDivStyle(divname);
-
if (divstyle.visibility == 'visible' || divstyle.visibility == 'show') {
-
divstyle.visibility = 'hidden';
-
} else {
-
fixPosition(divname);
-
divstyle.visibility = 'visible';
-
}
-
}
-
-
function setPosition(elt,positionername,isPlacedUnder) {
-
var positioner;
-
if (isIE) {
-
positioner = document.all[positionername];
-
} else {
-
if (isDOM) {
-
positioner = document.getElementById(positionername);
-
} else {
-
positioner = document.images[positionername];
-
}
-
}
-
elt.left = getAbsX(positioner);
-
elt.top = getAbsY(positioner) + (isPlacedUnder ? positioner.height : 0);
-
}
-
************************************************** ********************************* calendar.html file:
[HTML]<html>
<head><title>DHTML Calendar</title>
<script language="JavaScript1.2" src="leisure_cal.js"></script>
<script language="JavaScript1.2" src="calendar.js"></script>
<script language="JavaScript1.2">
<!--
function fixPosition(divname) {
divstyle = getDivStyle(divname);
positionerImgName = divname + 'Pos';
isPlacedUnder = false;
if (isPlacedUnder) {
setPosition(divstyle,positionerImgName,true);
} else {
setPosition(divstyle,positionerImgName)
}
}
function toggleDatePicker(eltName,formElt) {
var x = formElt.indexOf('.');
var formName = formElt.substring(0,x);
var formEltName = formElt.substring(x+1);
newCalendar(eltName,document.forms[formName].elements[formEltName]);
toggleVisible(eltName);
}
function fixPositions()
{
fixPosition('daysOfMonth');
fixPosition('daysOfMonth2');
}
// -->
</script>
</head>
<body onresize="fixPositions()">
<form name="date">
<center>
<table border=0>
<tr>
<td>Pick-Up Date: </td>
<td><INPUT name=ret size="10" onmouseup="toggleDatePicker('daysOfMonth','date.re t')" id=daysOfMonthPos name=daysOfMonthPos align=absmiddle><div id="daysOfMonth" style="position:absolute;"></div></td>
</tr>
<tr>
<td>Return Date: </td>
<td><INPUT name=ret2 size="10" onmouseup="toggleDatePicker('daysOfMonth2','date.r et2')" id=daysOfMonth2Pos name=daysOfMonth2Pos align=absmiddle><div id="daysOfMonth2" style="position:absolute;"></div></td>
</tr>
</table>
</center>
</form>
<SCRIPT language=JavaScript1.2>
function Cancel() {
hideElement("daysOfMonth");
}
</SCRIPT>
<script language="JavaScript1.2">
<!--
hideElement('daysOfMonth');
hideElement('daysOfMonth2');
//-->
</script>[/HTML]
Threads merged. Please do not double post.
Copy and Paste all bottom code and save it as .html file so that you can preview it on browser to fix it. I have two month calendar code. Currently calendar months show up at top and bottom. I want to fix it so that calendar months show up side by side (months parallel to each other instate of at top and bottom).
------------------------------------------------------------------------------------------------------
[HTML]<html>
<head><title>Calendar</title>
<script language="JavaScript1.2">
//**************************** DHTML CODE
isIE = (document.all ? true : false);
isDOM = (document.getElementById ? true : false);
function getAbsX(elt) { return (elt.x) ? elt.x : getAbsPos(elt,"Left"); }
function getAbsY(elt) { return (elt.y) ? elt.y : getAbsPos(elt,"Top"); }
function getAbsPos(elt,which) {
iPos = 0; //This will move DIV away from input field.
while (elt != null) {
iPos += elt["offset" + which];
elt = elt.offsetParent;
}
return iPos;
}
function getDivStyle(divname) {
var style;
if (isDOM) { style = document.getElementById(divname).style; }
else { style = isIE ? document.all[divname].style
: document.layers[divname]; }
return style;
}
function hideElement(divname) {
getDivStyle(divname).visibility = 'hidden';
}
function moveBy(elt,deltaX,deltaY) {
elt.left = parseInt(elt.left) + deltaX;
elt.top = parseInt(elt.top) + deltaY;
}
function toggleVisible(divname) {
divstyle = getDivStyle(divname);
if (divstyle.visibility == 'visible' || divstyle.visibility == 'show') {
divstyle.visibility = 'hidden';
} else {
fixPosition(divname);
divstyle.visibility = 'visible';
}
}
function setPosition(elt,positionername,isPlacedUnder) {
var positioner;
if (isIE) {
positioner = document.all[positionername];
} else {
if (isDOM) {
positioner = document.getElementById(positionername);
} else {
positioner = document.images[positionername];
}
}
elt.left = getAbsX(positioner);
elt.top = getAbsY(positioner) + (isPlacedUnder ? positioner.height : 0);
}
//**************************** DHTML CODE - END
//**************************** Javascript CODE
isIE = (document.all ? true : false);
isDOM = (document.getElementById ? true : false);
// Initializing arrays
var months = new Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul",
"Aug", "Sep", "Oct", "Nov", "Dec");
var daysInMonth = new Array(31, 28, 31, 30, 31, 30, 31, 31,
30, 31, 30, 31);
var displayMonth = new Date().getMonth();
var displayYear = new Date().getFullYear();
var displayDivName;
var displayElement;
function getDays(month, year) {
// Check for leap year when February is selected
if (1 == month)
return ((0 == year % 4) && (0 != (year % 100))) ||
(0 == year % 400) ? 29 : 28;
else
return daysInMonth[month];
}
function getToday(d) {
// Create today's date.
this.now = (d)?d:new Date();
this.year = this.now.getFullYear();
this.month = this.now.getMonth();
this.day = this.now.getDate();
}
// Start calendar with today
today = new getToday();
function newCalendar(eltName,attachedElement) {
if (attachedElement) {
if (displayDivName && displayDivName != eltName) hideElement(displayDivName);
displayElement = attachedElement;
}
displayDivName = eltName;
today = new getToday();
var parseYear = parseInt(displayYear + '');
var newCal = new Date(parseYear,displayMonth,1);
var day = -1;
var startDayOfWeek = newCal.getDay();
if ((today.year == newCal.getFullYear()) &&
(today.month == newCal.getMonth()))
{
day = today.day;
}
var intDaysInMonth =
getDays(newCal.getMonth(), newCal.getFullYear());
var daysGrid = makeDaysGridA(startDayOfWeek,day,intDaysInMonth,ne wCal,eltName)
// next month
newCal.setMonth(newCal.getMonth()+1) //imp
day = -1;
startDayOfWeek = newCal.getDay();
if ((today.year == newCal.getFullYear()) &&
(today.month == newCal.getMonth())) {
day = today.day;
}
intDaysInMonth = getDays(newCal.getMonth(), newCal.getFullYear());
daysGrid += makeDaysGridA(startDayOfWeek,day,intDaysInMonth,ne wCal,eltName)
if (isIE) {
var elt = document.all[eltName];
elt.innerHTML = daysGrid;
} else if (isDOM) {
var elt = document.getElementById(eltName);
elt.innerHTML = daysGrid;
} else {
var elt = document.layers[eltName].document;
elt.open();
elt.write(daysGrid);
elt.close();
}
}
function incMonth(delta,eltName) {
displayMonth += delta;
if (displayMonth >= 12) {
displayMonth = 0;
incYear(1,eltName);
} else if (displayMonth <= -1) {
displayMonth = 11;
incYear(-1,eltName);
} else {
newCalendar(eltName);
}
}
function incYear(delta,eltName) {
displayYear = parseInt(displayYear + '') + delta;
newCalendar(eltName);
}
function makeDaysGridA(startDay,day,intDaysInMonth,newCal,e ltName) {
var daysGrid;
var month = newCal.getMonth();
var year = newCal.getFullYear();
var isThisYear = (year == new Date().getFullYear());
var isThisMonth = (day > -1)
daysGrid = '<table border=1 cellspacing=0 cellpadding=2><tr><td bgcolor=#ffffff nowrap>';
daysGrid += '<font face="courier new, courier" size=2>';
daysGrid += ' ';
if (isThisMonth) {daysGrid += ' ';}
else
{daysGrid += '<a href="javascript:incMonth(-1,\'' + eltName + '\')"><<</a>';}
daysGrid += '<b>';
if (isThisMonth) { daysGrid += '<font color=#ffcc00>' + months[month] + '</font>'; }
else { daysGrid += months[month]; }
daysGrid += '</b>';
daysGrid += ' <b>' + year + '</b>';
daysGrid += '<a href="javascript:incMonth(1,\'' + eltName + '\')">>></a>';
daysGrid += ' ';
daysGrid += '<br><b>S M T W T F S </b><br>';
var dayOfMonthOfFirstSunday = (7 - startDay + 1);
for (var intWeek = 0; intWeek < 6; intWeek++) {
var dayOfMonth;
for (var intDay = 0; intDay < 7; intDay++) {
dayOfMonth = (intWeek * 7) + intDay + dayOfMonthOfFirstSunday - 7;
if (dayOfMonth <= 0) {
daysGrid += " ";
} else if (dayOfMonth <= intDaysInMonth) {
var color = "#3366AA";
if (day > 0 && day == dayOfMonth) color="#ffcc00";
daysGrid += '<a href="javascript:setDay(';
daysGrid += year + ','
daysGrid += (month+1) + ','
daysGrid += dayOfMonth + ',\'' + eltName + '\')" '
daysGrid += 'style="color:' + color + '">';
var dayString = dayOfMonth + "</a> ";
if (dayString.length == 6) dayString = '0' + dayString;
daysGrid += dayString;
}
}
if (dayOfMonth < intDaysInMonth) daysGrid += "<br>";
}
return daysGrid + "</td></tr>";
}
function setDay(year,month,day,eltName) {
displayElement.value = month + "/" + day + "/" + year;
hideElement(eltName);
}
//**************************** Javascript CODE - END
//*************************** HTML CODE - START
<!--
function fixPosition(divname) {
divstyle = getDivStyle(divname);
positionerImgName = divname + 'Pos';
isPlacedUnder = false;
if (isPlacedUnder) {
setPosition(divstyle,positionerImgName,true);
} else {
setPosition(divstyle,positionerImgName)
}
}
function toggleDatePicker(eltName,formElt) {
var x = formElt.indexOf('.');
var formName = formElt.substring(0,x);
var formEltName = formElt.substring(x+1);
newCalendar(eltName,document.forms[formName].elements[formEltName]);
toggleVisible(eltName);
}
function fixPositions()
{
fixPosition('daysOfMonth');
fixPosition('daysOfMonth2');
}
// -->
</script>
</head>
<body onresize="fixPositions()">
<form name="date">
<center>
<table border=0>
<tr>
<td>Pick-Up Date: </td>
<td><INPUT name=ret size="10" onmouseup="toggleDatePicker('daysOfMonth','date.re t')" id=daysOfMonthPos name=daysOfMonthPos align=absmiddle><div id="daysOfMonth" style="position:absolute;"></div></td>
</tr>
<tr>
<td>Return Date: </td>
<td><INPUT name=ret2 size="10" onmouseup="toggleDatePicker('daysOfMonth2','date.r et2')" id=daysOfMonth2Pos name=daysOfMonth2Pos align=absmiddle><div id="daysOfMonth2" style="position:absolute;"></div></td>
</tr>
</table>
</center>
</form>
<SCRIPT language=JavaScript1.2>
function Cancel() {
hideElement("daysOfMonth");
}
</SCRIPT>
<script language="JavaScript1.2">
<!--
hideElement('daysOfMonth');
hideElement('daysOfMonth2');
//-->
</script>[/HTML]
Merged yet another thread. If you have some new information, post in the same thread. Do not start another thread for every single post.
This has been fixed so no need to put time towards it. This has been fixed so no need to put time towards it.
It's good that you got it working. What particular solution worked for you?
Sign in to post your reply or Sign up for a free account.
Similar topics
by: vinu |
last post by:
I have a javascript file named select.js. This is a file which is use
to pop up a calendar, when clicked on a calendar icon in an ASP file.
have a close button in the calendar. When i click on the...
|
by: Stimp |
last post by:
preferably one that when clicked can update three date dropdowns (day,
month, year) like
http://www.visitdublin.com/carhire/avis.asp
Don't mind paying for the file... anyone seen something...
|
by: Geoff Cox |
last post by:
Hello,
The code below is aimed at passing the date in the yyyyMMdd format
from the javascript calendar in an html file to the php in a another
file which then searches a MySQL database.
For...
|
by: Bob Sanderson |
last post by:
I have a PHP web page which uses a HTML form. I would like to enter dates
into the date fields using a JavaScript calendar, similar to the way
phpMyAdmin does. Can anyone recommend a JavaScript...
|
by: sorobor |
last post by:
dear sir ..
i am using cakephp freamwork ..By the way i m begener in php and javascript ..
My probs r bellow
I made a javascript calender ..there is a close button ..when i press close button...
|
by: gan |
last post by:
hi dear all
please help me
im using the calander control from a form
just i paste here the problem,
the problem is when i click the calander button the calander is opening at the same time...
|
by: KRISHNA PRAVI |
last post by:
the error is "runtime error object expected" here is the code.......................................................................................
<script language="javascript"...
|
by: swethak |
last post by:
hi,
i have a code to disply the calendar and add events to that. It works fine.But my requirement is to i have to disply a weekly and daily calendar.Any body plz suggest that what modifications i...
|
by: xtremebass |
last post by:
Hello Bytes,
i have a calender program which is created by using Javascript. when i execute that program using Internet Explorer,it works properly but when i tried in Mozilla firefox it didnt...
|
by: erikbower65 |
last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps:
1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal.
2. Connect to...
|
by: linyimin |
last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
|
by: erikbower65 |
last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA:
1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
|
by: kcodez |
last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
|
by: Taofi |
last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same
This are my field names
ID, Budgeted, Actual, Status and Differences
...
|
by: DJRhino1175 |
last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this -
If...
|
by: Rina0 |
last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
|
by: DJRhino |
last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer)
If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _
310030356 Or 310030359 Or 310030362 Or...
|
by: DJRhino |
last post by:
Was curious if anyone else was having this same issue or not....
I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
| |