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 3803
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: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |