472,789 Members | 1,050 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,789 software developers and data experts.

JavaScript two month calendar help.

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:

Expand|Select|Wrap|Line Numbers
  1. isIE = (document.all ? true : false);
  2. isDOM = (document.getElementById ? true : false);
  3.  
  4. // Initializing arrays
  5. var months = new Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul",
  6.      "Aug", "Sep", "Oct", "Nov", "Dec", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul",
  7.      "Aug", "Sep", "Oct", "Nov", "Dec");
  8. var daysInMonth = new Array(31, 28, 31, 30, 31, 30, 31, 31,
  9.             30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31,
  10.             30, 31, 30, 31);
  11.  
  12. var displayMonth = new Date().getMonth();
  13. var displayYear = new Date().getFullYear();
  14. var displayDivName;
  15. var displayElement;
  16.  
  17. function getDays(month, year) {
  18. // Check for leap year when February is selected
  19.     if (1 == month)
  20.         return ((0 == year % 4) && (0 != (year % 100))) ||
  21.                (0 == year % 400) ? 29 : 28;
  22.     else
  23.          return daysInMonth[month];
  24.  
  25.     }
  26.  
  27. function getToday() {
  28.     // Create today's date.
  29.     this.now = new Date();
  30.     this.year = this.now.getFullYear();
  31.     this.month = this.now.getMonth();
  32.     this.day = this.now.getDate();
  33.     }
  34.  
  35. // Start calendar with today
  36.     today = new getToday();
  37.  
  38. function newCalendar(eltName,attachedElement) {
  39.     if (attachedElement) {
  40.         if (displayDivName && displayDivName != eltName) hideElement(displayDivName);
  41.            displayElement = attachedElement;
  42.         }
  43.  
  44.         displayDivName = eltName;
  45.             today = new getToday();
  46.             var parseYear = parseInt(displayYear + '');
  47.             var newCal = new Date(parseYear,displayMonth,1);
  48.             var day = -1;
  49.             var startDayOfWeek = newCal.getDay();
  50.  
  51.             if ((today.year == newCal.getFullYear()) &&
  52.                   (today.month == newCal.getMonth()))
  53.             {
  54.                day = today.day;
  55.             }
  56.  
  57.             var intDaysInMonth =
  58.                getDays(newCal.getMonth(), newCal.getFullYear());
  59.  
  60.  
  61.             var daysGrid = makeDaysGrid(startDayOfWeek,day,intDaysInMonth,newCal,eltName) 
  62.  
  63.         if (isIE) {
  64.            var elt = document.all[eltName];
  65.            elt.innerHTML = daysGrid;
  66.             } else if (isDOM) {
  67.            var elt = document.getElementById(eltName);
  68.            elt.innerHTML = daysGrid;
  69.         } else {
  70.            var elt = document.layers[eltName].document;
  71.            elt.open();
  72.            elt.write(daysGrid);
  73.            elt.close();
  74.         }
  75.      }
  76.  
  77.      function incMonth(delta,eltName) {
  78.          displayMonth = displayMonth+delta;
  79.                if (displayMonth >= 12) {
  80.                  displayMonth = 0;
  81.                  incYear(1,eltName);
  82.                } else if (displayMonth <= -1) {
  83.                  displayMonth = 11;
  84.                  incYear(-1,eltName);
  85.                } else {
  86.                  newCalendar(eltName);
  87.            }
  88.     }
  89.  
  90.      function incYear(delta,eltName) {
  91.        displayYear = parseInt(displayYear + '') + delta;
  92.        newCalendar(eltName);
  93.      }
  94.  
  95.      function makeDaysGrid(startDay,day,intDaysInMonth,newCal,eltName) {
  96.         var daysGrid;
  97.         var month = newCal.getMonth();
  98.         var year = newCal.getFullYear();
  99.         var isThisYear = (year == new Date().getFullYear());
  100.         var isThisMonth = (day > -1)
  101.  
  102.         daysGrid = '<table border=1 cellspacing=0 cellpadding=2><tr><td bgcolor=#ffffff nowrap>';
  103.         daysGrid += '<font face="courier new, courier" size=2>';
  104.         daysGrid += '&nbsp;&nbsp;';
  105.  
  106.         if (isThisMonth) {daysGrid += '&nbsp;&nbsp;';}
  107.         else
  108.         {daysGrid += '<a href="javascript:incMonth(-1,\'' + eltName + '\')"><img src="https://images.hertz.com/misc/arrow_lft.gif" border="0" valign="bottom"></a>';}
  109.  
  110.         daysGrid += '<b>';
  111.         if (isThisMonth) { daysGrid += '<font color=#ffcc00>' + months[month] + '</font>'; }
  112.         else { daysGrid += months[month]; }
  113.         daysGrid += '</b>';
  114.  
  115.         daysGrid += '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
  116.         daysGrid += months[month+1]; 
  117.  
  118.         daysGrid += '<a href="javascript:incMonth(1,\'' + eltName + '\')"><img src="https://images.hertz.com/misc/arrow_rgt.gif" border="0" valign="bottom"></a>';
  119.         daysGrid += '&nbsp;&nbsp;&nbsp;';
  120.  
  121.         daysGrid += '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="javascript:hideElement(\'' + eltName + '\')">x</a><br>';
  122.         daysGrid += '<b>&nbsp;S&nbsp; M&nbsp; T&nbsp; W&nbsp; T&nbsp; F&nbsp; S&nbsp;</b>&nbsp;&nbsp;&nbsp;<br>';
  123.  
  124.  
  125.         var dayOfMonthOfFirstSunday = (7 - startDay + 1);
  126.         for (var intWeek = 0; intWeek < 6; intWeek++) {
  127.             var dayOfMonth;
  128.             for (var intDay = 0; intDay < 7; intDay++) {
  129.                 dayOfMonth = (intWeek * 7) + intDay + dayOfMonthOfFirstSunday - 7;
  130.  
  131.                      if (dayOfMonth <= 0) {
  132.                            daysGrid += "&nbsp;&nbsp; ";
  133.                      } else if (dayOfMonth <= intDaysInMonth) {
  134.                            var color = "#3366AA";
  135.                        if (day > 0 && day == dayOfMonth) color="#ffcc00";
  136.  
  137.                            daysGrid += '<a href="javascript:setDay(';
  138.                            daysGrid += dayOfMonth + ',\'' + eltName + '\')" '
  139.                            daysGrid += 'style="color:' + color + '">';
  140.                            var dayString = dayOfMonth + "</a> ";
  141.                            if (dayString.length == 6) dayString = '0' + dayString;
  142.                            daysGrid += dayString;
  143.                     }
  144.            }
  145.  
  146.  
  147.            if (dayOfMonth < intDaysInMonth) daysGrid += "<br>&nbsp;";
  148.         }
  149.  
  150.  
  151.  
  152.     daysGrid += '<br><br>' + months[month+1]  + '<br>'; 
  153.  
  154.         daysGrid += '<br><b>&nbsp;S&nbsp; M&nbsp; T&nbsp; W&nbsp; T&nbsp; F&nbsp; S&nbsp;</b><br>&nbsp;';
  155.  
  156.  
  157.         var dayOfMonthOfFirstSunday = (7 - startDay + 1);
  158.         for (var intWeek = 0; intWeek < 6; intWeek++) {
  159.             var dayOfMonth;
  160.             for (var intDay = 0; intDay < 7; intDay++) {
  161.                 dayOfMonth = (intWeek * 7) + intDay + dayOfMonthOfFirstSunday - 7;
  162.  
  163.                      if (dayOfMonth <= 0) {
  164.                            daysGrid += "&nbsp;&nbsp; ";
  165.                      } else if (dayOfMonth <= intDaysInMonth) {
  166.                            var color = "#3366AA";
  167.                        if (day > 0 && day == dayOfMonth) color="#ffcc00";
  168.  
  169.                            daysGrid += '<a href="javascript:setDay(';
  170.                            daysGrid += dayOfMonth + ',\'' + eltName + '\')" '
  171.                            daysGrid += 'style="color:' + color + '">';
  172.                            var dayString = dayOfMonth + "</a> ";
  173.                            if (dayString.length == 6) dayString = '0' + dayString;
  174.                            daysGrid += dayString;
  175.                     }
  176.            }
  177.  
  178.  
  179.            if (dayOfMonth < intDaysInMonth) daysGrid += "<br>&nbsp;";
  180.         }
  181.  
  182.  
  183.  
  184.         return daysGrid + "</td></tr></table>";
  185.      }
  186.  
  187.  
  188.      function setDay(day,eltName) {
  189.        displayElement.value = (displayMonth + 1) + "/" + day + "/" + displayYear;
  190.        hideElement(eltName);
  191.      }
  192.  
************************************************** **********************************
leisure_cal.js file:

Expand|Select|Wrap|Line Numbers
  1. isIE = (document.all ? true : false);
  2. isDOM = (document.getElementById ? true : false);
  3. function getAbsX(elt) { return (elt.x) ? elt.x : getAbsPos(elt,"Left"); }
  4. function getAbsY(elt) { return (elt.y) ? elt.y : getAbsPos(elt,"Top"); }
  5.  
  6. function getAbsPos(elt,which) {
  7.  iPos = 0;
  8.  while (elt != null) {
  9.   iPos += elt["offset" + which];
  10.   elt = elt.offsetParent;
  11.  }
  12.  return iPos;
  13. }
  14.  
  15. function getDivStyle(divname) {
  16.  var style;
  17.  if (isDOM) { style = document.getElementById(divname).style; }
  18.  else { style = isIE ? document.all[divname].style
  19.                      : document.layers[divname]; }
  20.  return style;
  21. }
  22.  
  23. function hideElement(divname) {
  24.  getDivStyle(divname).visibility = 'hidden';
  25. }
  26.  
  27. function moveBy(elt,deltaX,deltaY) {
  28.  elt.left = parseInt(elt.left) + deltaX;
  29.  elt.top = parseInt(elt.top) + deltaY;
  30. }
  31.  
  32. function toggleVisible(divname) {
  33.  divstyle = getDivStyle(divname);
  34.  if (divstyle.visibility == 'visible' || divstyle.visibility == 'show') {
  35.    divstyle.visibility = 'hidden';
  36.  } else {
  37.    fixPosition(divname);
  38.    divstyle.visibility = 'visible';
  39.  }
  40. }
  41.  
  42. function setPosition(elt,positionername,isPlacedUnder) {
  43.  var positioner;
  44.  if (isIE) {
  45.   positioner = document.all[positionername];
  46.  } else {
  47.   if (isDOM) {
  48.     positioner = document.getElementById(positionername);
  49.   } else {
  50.     positioner = document.images[positionername];
  51.   }
  52.  }
  53.  elt.left = getAbsX(positioner);
  54.  elt.top = getAbsY(positioner) + (isPlacedUnder ? positioner.height : 0);
  55. }
  56.  
************************************************** *********************************
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:&nbsp;</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:&nbsp;</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]
May 26 '07 #1
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:

Expand|Select|Wrap|Line Numbers
  1. isIE = (document.all ? true : false);
  2. isDOM = (document.getElementById ? true : false);
  3.  
  4. // Initializing arrays
  5. var months = new Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul",
  6. "Aug", "Sep", "Oct", "Nov", "Dec", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul",
  7. "Aug", "Sep", "Oct", "Nov", "Dec");
  8. var daysInMonth = new Array(31, 28, 31, 30, 31, 30, 31, 31,
  9. 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31,
  10. 30, 31, 30, 31);
  11.  
  12. var displayMonth = new Date().getMonth();
  13. var displayYear = new Date().getFullYear();
  14. var displayDivName;
  15. var displayElement;
  16.  
  17. function getDays(month, year) {
  18. // Check for leap year when February is selected
  19. if (1 == month)
  20. return ((0 == year % 4) && (0 != (year % 100))) ||
  21. (0 == year % 400) ? 29 : 28;
  22. else
  23. return daysInMonth[month];
  24.  
  25. }
  26.  
  27. function getToday() {
  28. // Create today's date.
  29. this.now = new Date();
  30. this.year = this.now.getFullYear();
  31. this.month = this.now.getMonth();
  32. this.day = this.now.getDate();
  33. }
  34.  
  35. // Start calendar with today
  36. today = new getToday();
  37.  
  38. function newCalendar(eltName,attachedElement) {
  39. if (attachedElement) {
  40. if (displayDivName && displayDivName != eltName) hideElement(displayDivName);
  41. displayElement = attachedElement;
  42. }
  43.  
  44. displayDivName = eltName;
  45. today = new getToday();
  46. var parseYear = parseInt(displayYear + '');
  47. var newCal = new Date(parseYear,displayMonth,1);
  48. var day = -1;
  49. var startDayOfWeek = newCal.getDay();
  50.  
  51. if ((today.year == newCal.getFullYear()) &&
  52. (today.month == newCal.getMonth()))
  53. {
  54. day = today.day;
  55. }
  56.  
  57. var intDaysInMonth =
  58. getDays(newCal.getMonth(), newCal.getFullYear());
  59.  
  60.  
  61. var daysGrid = makeDaysGrid(startDayOfWeek,day,intDaysInMonth,new Cal,eltName) 
  62.  
  63. if (isIE) {
  64. var elt = document.all[eltName];
  65. elt.innerHTML = daysGrid;
  66. } else if (isDOM) {
  67. var elt = document.getElementById(eltName);
  68. elt.innerHTML = daysGrid;
  69. } else {
  70. var elt = document.layers[eltName].document;
  71. elt.open();
  72. elt.write(daysGrid);
  73. elt.close();
  74. }
  75. }
  76.  
  77. function incMonth(delta,eltName) {
  78. displayMonth = displayMonth+delta;
  79. if (displayMonth >= 12) {
  80. displayMonth = 0;
  81. incYear(1,eltName);
  82. } else if (displayMonth <= -1) {
  83. displayMonth = 11;
  84. incYear(-1,eltName);
  85. } else {
  86. newCalendar(eltName);
  87. }
  88. }
  89.  
  90. function incYear(delta,eltName) {
  91. displayYear = parseInt(displayYear + '') + delta;
  92. newCalendar(eltName);
  93. }
  94.  
  95. function makeDaysGrid(startDay,day,intDaysInMonth,newCal,el tName) {
  96. var daysGrid;
  97. var month = newCal.getMonth();
  98. var year = newCal.getFullYear();
  99. var isThisYear = (year == new Date().getFullYear());
  100. var isThisMonth = (day > -1)
  101.  
  102. daysGrid = '<table border=1 cellspacing=0 cellpadding=2><tr><td bgcolor=#ffffff nowrap>';
  103. daysGrid += '<font face="courier new, courier" size=2>';
  104. daysGrid += '&nbsp;&nbsp;';
  105.  
  106. if (isThisMonth) {daysGrid += '&nbsp;&nbsp;';}
  107. else
  108. {daysGrid += '<a href="javascript:incMonth(-1,\'' + eltName + '\')"><img src="https://images.hertz.com/misc/arrow_lft.gif" border="0" valign="bottom"></a>';}
  109.  
  110. daysGrid += '<b>';
  111. if (isThisMonth) { daysGrid += '<font color=#ffcc00>' + months[month] + '</font>'; }
  112. else { daysGrid += months[month]; }
  113. daysGrid += '</b>';
  114.  
  115. daysGrid += '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
  116. daysGrid += months[month+1]; 
  117.  
  118. daysGrid += '<a href="javascript:incMonth(1,\'' + eltName + '\')"><img src="https://images.hertz.com/misc/arrow_rgt.gif" border="0" valign="bottom"></a>';
  119. daysGrid += '&nbsp;&nbsp;&nbsp;';
  120.  
  121. daysGrid += '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="javascript:hideElement(\'' + eltName + '\')">x</a><br>';
  122. daysGrid += '<b>&nbsp;S&nbsp; M&nbsp; T&nbsp; W&nbsp; T&nbsp; F&nbsp; S&nbsp;</b>&nbsp;&nbsp;&nbsp;<br>';
  123.  
  124.  
  125. var dayOfMonthOfFirstSunday = (7 - startDay + 1);
  126. for (var intWeek = 0; intWeek < 6; intWeek++) {
  127. var dayOfMonth;
  128. for (var intDay = 0; intDay < 7; intDay++) {
  129. dayOfMonth = (intWeek * 7) + intDay + dayOfMonthOfFirstSunday - 7;
  130.  
  131. if (dayOfMonth <= 0) {
  132. daysGrid += "&nbsp;&nbsp; ";
  133. } else if (dayOfMonth <= intDaysInMonth) {
  134. var color = "#3366AA";
  135. if (day > 0 && day == dayOfMonth) color="#ffcc00";
  136.  
  137. daysGrid += '<a href="javascript:setDay(';
  138. daysGrid += dayOfMonth + ',\'' + eltName + '\')" '
  139. daysGrid += 'style="color:' + color + '">';
  140. var dayString = dayOfMonth + "</a> ";
  141. if (dayString.length == 6) dayString = '0' + dayString;
  142. daysGrid += dayString;
  143. }
  144. }
  145.  
  146.  
  147. if (dayOfMonth < intDaysInMonth) daysGrid += "<br>&nbsp;";
  148. }
  149.  
  150.  
  151.  
  152. daysGrid += '<br><br>' + months[month+1] + '<br>'; 
  153.  
  154. daysGrid += '<br><b>&nbsp;S&nbsp; M&nbsp; T&nbsp; W&nbsp; T&nbsp; F&nbsp; S&nbsp;</b><br>&nbsp;';
  155.  
  156.  
  157. var dayOfMonthOfFirstSunday = (7 - startDay + 1);
  158. for (var intWeek = 0; intWeek < 6; intWeek++) {
  159. var dayOfMonth;
  160. for (var intDay = 0; intDay < 7; intDay++) {
  161. dayOfMonth = (intWeek * 7) + intDay + dayOfMonthOfFirstSunday - 7;
  162.  
  163. if (dayOfMonth <= 0) {
  164. daysGrid += "&nbsp;&nbsp; ";
  165. } else if (dayOfMonth <= intDaysInMonth) {
  166. var color = "#3366AA";
  167. if (day > 0 && day == dayOfMonth) color="#ffcc00";
  168.  
  169. daysGrid += '<a href="javascript:setDay(';
  170. daysGrid += dayOfMonth + ',\'' + eltName + '\')" '
  171. daysGrid += 'style="color:' + color + '">';
  172. var dayString = dayOfMonth + "</a> ";
  173. if (dayString.length == 6) dayString = '0' + dayString;
  174. daysGrid += dayString;
  175. }
  176. }
  177.  
  178.  
  179. if (dayOfMonth < intDaysInMonth) daysGrid += "<br>&nbsp;";
  180. }
  181.  
  182.  
  183.  
  184. return daysGrid + "</td></tr></table>";
  185. }
  186.  
  187.  
  188. function setDay(day,eltName) {
  189. displayElement.value = (displayMonth + 1) + "/" + day + "/" + displayYear;
  190. hideElement(eltName);
  191. }
  192.  
************************************************** **********************************
leisure_cal.js file:

Expand|Select|Wrap|Line Numbers
  1. isIE = (document.all ? true : false);
  2. isDOM = (document.getElementById ? true : false);
  3. function getAbsX(elt) { return (elt.x) ? elt.x : getAbsPos(elt,"Left"); }
  4. function getAbsY(elt) { return (elt.y) ? elt.y : getAbsPos(elt,"Top"); }
  5.  
  6. function getAbsPos(elt,which) {
  7. iPos = 0;
  8. while (elt != null) {
  9. iPos += elt["offset" + which];
  10. elt = elt.offsetParent;
  11. }
  12. return iPos;
  13. }
  14.  
  15. function getDivStyle(divname) {
  16. var style;
  17. if (isDOM) { style = document.getElementById(divname).style; }
  18. else { style = isIE ? document.all[divname].style
  19. : document.layers[divname]; }
  20. return style;
  21. }
  22.  
  23. function hideElement(divname) {
  24. getDivStyle(divname).visibility = 'hidden';
  25. }
  26.  
  27. function moveBy(elt,deltaX,deltaY) {
  28. elt.left = parseInt(elt.left) + deltaX;
  29. elt.top = parseInt(elt.top) + deltaY;
  30. }
  31.  
  32. function toggleVisible(divname) {
  33. divstyle = getDivStyle(divname);
  34. if (divstyle.visibility == 'visible' || divstyle.visibility == 'show') {
  35. divstyle.visibility = 'hidden';
  36. } else {
  37. fixPosition(divname);
  38. divstyle.visibility = 'visible';
  39. }
  40. }
  41.  
  42. function setPosition(elt,positionername,isPlacedUnder) {
  43. var positioner;
  44. if (isIE) {
  45. positioner = document.all[positionername];
  46. } else {
  47. if (isDOM) {
  48. positioner = document.getElementById(positionername);
  49. } else {
  50. positioner = document.images[positionername];
  51. }
  52. }
  53. elt.left = getAbsX(positioner);
  54. elt.top = getAbsY(positioner) + (isPlacedUnder ? positioner.height : 0);
  55. }
  56.  
************************************************** *********************************
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:&nbsp;</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:&nbsp;</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]
May 27 '07 #2
acoder
16,027 Expert Mod 8TB
Threads merged. Please do not double post.
May 27 '07 #3
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 += '&nbsp;&nbsp;';

if (isThisMonth) {daysGrid += '&nbsp;&nbsp;';}
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 += '&nbsp;<b>' + year + '</b>';

daysGrid += '<a href="javascript:incMonth(1,\'' + eltName + '\')">>></a>';
daysGrid += '&nbsp;&nbsp;&nbsp;';

daysGrid += '<br><b>S&nbsp; M&nbsp; T&nbsp; W&nbsp; T&nbsp; F&nbsp; S&nbsp;</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 += "&nbsp;&nbsp;&nbsp;";
} 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:&nbsp;</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:&nbsp;</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]
May 28 '07 #4
acoder
16,027 Expert Mod 8TB
Merged yet another thread. If you have some new information, post in the same thread. Do not start another thread for every single post.
May 28 '07 #5
acoder
16,027 Expert Mod 8TB
Read about element positions.
May 28 '07 #6
This has been fixed so no need to put time towards it.
May 29 '07 #7
acoder
16,027 Expert Mod 8TB
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?
May 30 '07 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

10
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...
19
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...
2
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...
3
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...
2
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...
11
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...
1
by: KRISHNA PRAVI | last post by:
the error is "runtime error object expected" here is the code....................................................................................... <script language="javascript"...
1
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...
1
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...
0
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...
0
linyimin
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...
0
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...
0
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...
0
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 ...
14
DJRhino1175
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...
0
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...
5
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...
2
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.