codeDude
07-08-2003, 08:12 AM
Folks,
I would be gratefull for any expert advice as to what is going wrong with the below calendar.
The calender accepts 2 date parameters, giving the lower and upper range of dates for the user to select. These valid dates *should* be coloured blue, with all other dates grayed.
The above works perfectly well when JUST the calender program is running [comment out the bottom calender call function to test], but when parameters are passed from the below HTML, the calender functions, but an if statement doesn't seem to work which checks to see if the text should be coloured blue.
There maybe some fundamental issue with dates which I dont understand ???
Thanks.
*** Program to Call the Calender up [Click on image] ***
<html>
<head>
<script>
minDate= new Date(2002,2,2)
maxDate= new Date(2003,9,9)
</script>
</head>
<body>
<form name="form1">
<table width="30%">
<tr>
<td><a href="#" onClick="javascript:var cal=window.open('cal.html','','scrollbars=no');cal.calendar(minDate,maxDate)"><img src="calendar.gif"></a></td>
</tr>
</table>
</form>
</body>
</html>
*** Calendar Program [works fine if not called from above program] ***
<HTML>
<style>
body {font-family:Arial; align:middle}
table {background-color:FFEC33}
#head td {color:black; background-color:F7D400; width:32}
div {color:blue; font-weight:bold; cursor:hand}
</style>
<BODY onResize="window.resizeTo(274,225)" leftMargin=0 rightMargin=0 topMargin=0 bottomMargin=0>
<FORM name="calendarForm">
<table style="text-align:center; font-size:12" cellspacing=0 cellpadding=1 border=0>
<tr style="background-color:F7D700; color:blue; cursor:hand">
<td id=Jan onClick="selectMonth(0)">Jan</td><td id=Feb onClick="selectMonth(1)">Feb</td><td id=Mar onClick="selectMonth(2)">Mar</td>
<td id=Apr onClick="selectMonth(3)">Apr</td><td id=May onClick="selectMonth(4)">May</td><td id=Jun onClick="selectMonth(5)">Jun</td>
<td id=Jul onClick="selectMonth(6)">Jul</td><td id=Aug onClick="selectMonth(7)">Aug</td><td id=Sep onClick="selectMonth(8)">Sep</td>
<td id=Oct onClick="selectMonth(9)">Oct</td><td id=Nov onClick="selectMonth(10)">Nov</td><td id=Dec onClick="selectMonth(11)">Dec</td>
</tr>
<tr><td colspan=12>
<table style="color:blue; text-align:center; font-size:14">
<tr><td id=monthTxt colspan=12 height=34 style='color:blue'><B>xxx</B> <select name=calendarYear onChange="selectYear()"></select></td></tr>
<tr id=head><td>Mon</td><td>Tue</td><td>Wed</td><td>Thu</td><td>Fri</td><td>Sat</td><td>Sun</td></tr>
<tr><td id=day1row1></td><td id=day2row1></td><td id=day3row1></td><td id=day4row1></td><td id=day5row1></td><td id=day6row1></td><td id=day7row1></td></tr>
<tr><td id=day1row2></td><td id=day2row2></td><td id=day3row2></td><td id=day4row2></td><td id=day5row2></td><td id=day6row2></td><td id=day7row2></td></tr>
<tr><td id=day1row3></td><td id=day2row3></td><td id=day3row3></td><td id=day4row3></td><td id=day5row3></td><td id=day6row3></td><td id=day7row3></td></tr>
<tr><td id=day1row4></td><td id=day2row4></td><td id=day3row4></td><td id=day4row4></td><td id=day5row4></td><td id=day6row4></td><td id=day7row4></td></tr>
<tr><td id=day1row5></td><td id=day2row5></td><td id=day3row5></td><td id=day4row5></td><td id=day5row5></td><td id=day6row5></td><td id=day7row5></td></tr>
<tr><td id=day1row6></td><td id=day2row6></td><td id=day3row6></td><td id=day4row6></td><td id=day5row6></td><td id=day6row6></td><td id=day7row6></td></tr>
</table>
</tr>
</table>
</form>
<script>
window.resizeTo(274,225)
window.moveTo(250,300)
monthsInYear = new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec") // Months to evaluate into objects
function calendar(minDt,maxDt) {
// Global
calendarMinDate= minDt
calendarMaxDate= maxDt
calendarSelectDate = new Date()
currentMonth=calendarSelectDate.getMonth()
// If current Month is December, then allow an extra year to be shown just in case any future dates may need to be selected
var addYear=1*(calendarMaxDate.getMonth() ==11)
for (var i=calendarMinDate.getFullYear(); i <= calendarMaxDate.getFullYear() + addYear; i++) {
calendarForm.calendarYear.options[calendarForm.calendarYear.options.length] = new Option (i,i)
if (calendarMaxDate.getFullYear() == i)
calendarForm.calendarYear.options[calendarForm.calendarYear.options.length -1].selected = true
}
updateCalendar()
}
function updateCalendar() {
// Get number of days in the month
var oneHour = 1000 * 60 * 60
var oneDay = oneHour * 24
var thisMonth = new Date(calendarSelectDate.getFullYear(), calendarSelectDate.getMonth(), 1) // Get 1st of Month
var nextMonth = new Date(calendarSelectDate.getFullYear(), calendarSelectDate.getMonth() + 1, 1) // Get 1st of Next Month
var daysInMonth = Math.ceil((nextMonth.getTime() - thisMonth.getTime() - oneHour) / oneDay) // Take into account time zones
monthTxt.innerHTML = "<B>" + monthsInYear[calendarSelectDate.getMonth()] + monthTxt.innerHTML.substr(6) // Change Month Text
eval(monthsInYear[currentMonth]).style.backgroundColor="F7D700" // Reset Last Selected Month Background Color
currentMonth=calendarSelectDate.getMonth()
eval(monthsInYear[calendarSelectDate.getMonth()]).style.backgroundColor="lime" // Set selected month background color
// Clear All Cells Before Repopulating
for (var row=1; row < 7; row++)
for (var day=1; day < 8; day++)
eval("day"+day+"row"+row).innerText = " " // Get cell ID & Set Cells Outside Calendar Range To a Space
// Get 1st Of Month Position Start
day=thisMonth.getDay()
if (day==0)
day=7 // Sunday is day 0, but is 7 in this calender
var row=1
for (var dy=1; dy < daysInMonth + 1; dy++) {
var tmpDate= new Date(calendarSelectDate.getFullYear(), calendarSelectDate.getMonth(), dy) // Compare Date for Range
var cellName = eval("day"+day+"row"+row)
// Below changes text to blue and allows mouse Click- Fail Point when called from another program
if ((tmpDate >= calendarMinDate) && (tmpDate <= calendarMaxDate))
cellName.innerHTML = "<div onClick='putDate(this.innerText)'>" + dy + "</div>"
else
cellName.innerHTML = "<B><font color=gray>" + dy + "</font></B>"
if (day++ ==7) {
day=1 // Reset to Monday
row++
}
}
}
function selectMonth(selMonth) {
calendarSelectDate = new Date(calendarForm.calendarYear.value,selMonth,1)
updateCalendar()
}
function selectYear() {
calendarSelectDate = new Date(calendarForm.calendarYear.value,currentMonth,1)
updateCalendar()
}
function putDate(day) {
if (day.length == 1)
day="0"+day
var month=monthsInYear[calendarSelectDate.getMonth()].toUpperCase()
var dateString=day + month + calendarSelectDate.getFullYear()
alert(dateString)
}
// Uncommenting below enables program to work correctly!
//calendar(new Date(2002,03,20),new Date(2003,06,03)) // Execute calendar
</script>
I would be gratefull for any expert advice as to what is going wrong with the below calendar.
The calender accepts 2 date parameters, giving the lower and upper range of dates for the user to select. These valid dates *should* be coloured blue, with all other dates grayed.
The above works perfectly well when JUST the calender program is running [comment out the bottom calender call function to test], but when parameters are passed from the below HTML, the calender functions, but an if statement doesn't seem to work which checks to see if the text should be coloured blue.
There maybe some fundamental issue with dates which I dont understand ???
Thanks.
*** Program to Call the Calender up [Click on image] ***
<html>
<head>
<script>
minDate= new Date(2002,2,2)
maxDate= new Date(2003,9,9)
</script>
</head>
<body>
<form name="form1">
<table width="30%">
<tr>
<td><a href="#" onClick="javascript:var cal=window.open('cal.html','','scrollbars=no');cal.calendar(minDate,maxDate)"><img src="calendar.gif"></a></td>
</tr>
</table>
</form>
</body>
</html>
*** Calendar Program [works fine if not called from above program] ***
<HTML>
<style>
body {font-family:Arial; align:middle}
table {background-color:FFEC33}
#head td {color:black; background-color:F7D400; width:32}
div {color:blue; font-weight:bold; cursor:hand}
</style>
<BODY onResize="window.resizeTo(274,225)" leftMargin=0 rightMargin=0 topMargin=0 bottomMargin=0>
<FORM name="calendarForm">
<table style="text-align:center; font-size:12" cellspacing=0 cellpadding=1 border=0>
<tr style="background-color:F7D700; color:blue; cursor:hand">
<td id=Jan onClick="selectMonth(0)">Jan</td><td id=Feb onClick="selectMonth(1)">Feb</td><td id=Mar onClick="selectMonth(2)">Mar</td>
<td id=Apr onClick="selectMonth(3)">Apr</td><td id=May onClick="selectMonth(4)">May</td><td id=Jun onClick="selectMonth(5)">Jun</td>
<td id=Jul onClick="selectMonth(6)">Jul</td><td id=Aug onClick="selectMonth(7)">Aug</td><td id=Sep onClick="selectMonth(8)">Sep</td>
<td id=Oct onClick="selectMonth(9)">Oct</td><td id=Nov onClick="selectMonth(10)">Nov</td><td id=Dec onClick="selectMonth(11)">Dec</td>
</tr>
<tr><td colspan=12>
<table style="color:blue; text-align:center; font-size:14">
<tr><td id=monthTxt colspan=12 height=34 style='color:blue'><B>xxx</B> <select name=calendarYear onChange="selectYear()"></select></td></tr>
<tr id=head><td>Mon</td><td>Tue</td><td>Wed</td><td>Thu</td><td>Fri</td><td>Sat</td><td>Sun</td></tr>
<tr><td id=day1row1></td><td id=day2row1></td><td id=day3row1></td><td id=day4row1></td><td id=day5row1></td><td id=day6row1></td><td id=day7row1></td></tr>
<tr><td id=day1row2></td><td id=day2row2></td><td id=day3row2></td><td id=day4row2></td><td id=day5row2></td><td id=day6row2></td><td id=day7row2></td></tr>
<tr><td id=day1row3></td><td id=day2row3></td><td id=day3row3></td><td id=day4row3></td><td id=day5row3></td><td id=day6row3></td><td id=day7row3></td></tr>
<tr><td id=day1row4></td><td id=day2row4></td><td id=day3row4></td><td id=day4row4></td><td id=day5row4></td><td id=day6row4></td><td id=day7row4></td></tr>
<tr><td id=day1row5></td><td id=day2row5></td><td id=day3row5></td><td id=day4row5></td><td id=day5row5></td><td id=day6row5></td><td id=day7row5></td></tr>
<tr><td id=day1row6></td><td id=day2row6></td><td id=day3row6></td><td id=day4row6></td><td id=day5row6></td><td id=day6row6></td><td id=day7row6></td></tr>
</table>
</tr>
</table>
</form>
<script>
window.resizeTo(274,225)
window.moveTo(250,300)
monthsInYear = new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec") // Months to evaluate into objects
function calendar(minDt,maxDt) {
// Global
calendarMinDate= minDt
calendarMaxDate= maxDt
calendarSelectDate = new Date()
currentMonth=calendarSelectDate.getMonth()
// If current Month is December, then allow an extra year to be shown just in case any future dates may need to be selected
var addYear=1*(calendarMaxDate.getMonth() ==11)
for (var i=calendarMinDate.getFullYear(); i <= calendarMaxDate.getFullYear() + addYear; i++) {
calendarForm.calendarYear.options[calendarForm.calendarYear.options.length] = new Option (i,i)
if (calendarMaxDate.getFullYear() == i)
calendarForm.calendarYear.options[calendarForm.calendarYear.options.length -1].selected = true
}
updateCalendar()
}
function updateCalendar() {
// Get number of days in the month
var oneHour = 1000 * 60 * 60
var oneDay = oneHour * 24
var thisMonth = new Date(calendarSelectDate.getFullYear(), calendarSelectDate.getMonth(), 1) // Get 1st of Month
var nextMonth = new Date(calendarSelectDate.getFullYear(), calendarSelectDate.getMonth() + 1, 1) // Get 1st of Next Month
var daysInMonth = Math.ceil((nextMonth.getTime() - thisMonth.getTime() - oneHour) / oneDay) // Take into account time zones
monthTxt.innerHTML = "<B>" + monthsInYear[calendarSelectDate.getMonth()] + monthTxt.innerHTML.substr(6) // Change Month Text
eval(monthsInYear[currentMonth]).style.backgroundColor="F7D700" // Reset Last Selected Month Background Color
currentMonth=calendarSelectDate.getMonth()
eval(monthsInYear[calendarSelectDate.getMonth()]).style.backgroundColor="lime" // Set selected month background color
// Clear All Cells Before Repopulating
for (var row=1; row < 7; row++)
for (var day=1; day < 8; day++)
eval("day"+day+"row"+row).innerText = " " // Get cell ID & Set Cells Outside Calendar Range To a Space
// Get 1st Of Month Position Start
day=thisMonth.getDay()
if (day==0)
day=7 // Sunday is day 0, but is 7 in this calender
var row=1
for (var dy=1; dy < daysInMonth + 1; dy++) {
var tmpDate= new Date(calendarSelectDate.getFullYear(), calendarSelectDate.getMonth(), dy) // Compare Date for Range
var cellName = eval("day"+day+"row"+row)
// Below changes text to blue and allows mouse Click- Fail Point when called from another program
if ((tmpDate >= calendarMinDate) && (tmpDate <= calendarMaxDate))
cellName.innerHTML = "<div onClick='putDate(this.innerText)'>" + dy + "</div>"
else
cellName.innerHTML = "<B><font color=gray>" + dy + "</font></B>"
if (day++ ==7) {
day=1 // Reset to Monday
row++
}
}
}
function selectMonth(selMonth) {
calendarSelectDate = new Date(calendarForm.calendarYear.value,selMonth,1)
updateCalendar()
}
function selectYear() {
calendarSelectDate = new Date(calendarForm.calendarYear.value,currentMonth,1)
updateCalendar()
}
function putDate(day) {
if (day.length == 1)
day="0"+day
var month=monthsInYear[calendarSelectDate.getMonth()].toUpperCase()
var dateString=day + month + calendarSelectDate.getFullYear()
alert(dateString)
}
// Uncommenting below enables program to work correctly!
//calendar(new Date(2002,03,20),new Date(2003,06,03)) // Execute calendar
</script>