473,416 Members | 1,778 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

JavaScript-Calender date cant displayed in Mozilla FireFox

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 worked.
Dates of particular year,month not displayed in that calender grids. i have collected that coding from online free resources.
Here i have attached code for your reference. please do suggest me how do i display the calender date in grids in Mozilla Firefox.

file Name:calender.html
Expand|Select|Wrap|Line Numbers
  1.  
  2. <html>
  3. <head>
  4. <script language="JavaScript">
  5. <!--
  6. var months = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
  7. var daysInMonth = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
  8. var days = new Array("S", "M", "T", "W", "T", "F", "S");
  9.  
  10. today = new getToday();    
  11. var element_id;
  12.  
  13. function getDays(month, year) 
  14. {
  15.     // Test for leap year when February is selected.
  16.     if (1 == month)
  17.         return ((0 == year % 4) && (0 != (year % 100))) ||
  18.             (0 == year % 400) ? 29 : 28;
  19.     else
  20.         return daysInMonth[month];
  21. }
  22.  
  23. function getToday()
  24. {
  25.     // Generate today's date.
  26.     this.now = new Date();
  27.     this.year = this.now.getFullYear() ; // Returned year XXXX
  28.     this.month = this.now.getMonth();
  29.     this.day = this.now.getDate();
  30. }
  31.  
  32.  
  33. function newCalendar() 
  34. {
  35.     var parseYear = parseInt(document.all.year  [document.all.year.selectedIndex].text);
  36.  
  37.     var newCal = new Date(parseYear , document.all.month.selectedIndex, 1);
  38.     var day = -1;
  39.     var startDay = newCal.getDay();
  40.     var daily = 0; 
  41.  
  42.     today = new getToday(); // 1st call
  43.     if ((today.year == newCal.getFullYear() ) &&   (today.month == newCal.getMonth()))
  44.        day = today.day;
  45.     // Cache the calendar table's tBody section, dayList.
  46.     var tableCal = document.all.calendar.tBodies.dayList;
  47.  
  48.     var intDaysInMonth =
  49.        getDays(newCal.getMonth(), newCal.getFullYear() );
  50.  
  51.     for (var intWeek = 0; intWeek < tableCal.rows.length;  intWeek++)
  52.            for (var intDay = 0;
  53.              intDay < tableCal.rows[intWeek].cells.length;
  54.              intDay++)
  55.      {
  56.           var cell = tableCal.rows[intWeek].cells[intDay];
  57.  
  58.           // Start counting days.
  59.           if ((intDay == startDay) && (0 == daily))
  60.              daily = 1;
  61.  
  62.           // Highlight the current day.
  63.           cell.style.color = (day == daily) ? "red" : "";
  64.           if(day == daily)
  65.           {
  66.                 document.all.todayday.innerText= "Today: " +  newCal.getFullYear()+ "-" + 
  67.                     (newCal.getMonth()+1) + "-" + day ;
  68.           }
  69.           // Output the day number into the cell.
  70.           if ((daily > 0) && (daily <= intDaysInMonth))
  71.              cell.innerText = daily++;
  72.           else
  73.              cell.innerText = "";
  74.        }
  75.  
  76. }
  77.  
  78.      function getTodayDay()
  79.      {
  80.                 document.all[element_id].value = today.year + "-" + (today.month+1) + 
  81.                     "-" + today.day ; 
  82.                 //document.all.calendar.style.visibility="hidden";
  83.                 document.all.calendar.style.display="none";
  84.                 document.all.year.selectedIndex =100;   
  85.                 document.all.month.selectedIndex = today.month; 
  86.      }
  87.  
  88.         function getDate() 
  89.          {
  90.             // This code executes when the user clicks on a day
  91.             // in the calendar.
  92.             if ("TD" == event.srcElement.tagName)
  93.                // Test whether day is valid.
  94.                if ("" != event.srcElement.innerText)
  95.                { 
  96.                  var mn = document.all.month.selectedIndex+1;
  97.                  var Year = document.all.year [document.all.year.selectedIndex].text;
  98.                  document.all[element_id].value=Year+"-"+mn +"-"  +event.srcElement.innerText;
  99.                  //document.all.calendar.style.visibility="hidden";
  100.                  document.all.calendar.style.display="none";
  101.              }
  102.          }
  103.  
  104. function GetBodyOffsetX(el_name, shift)
  105. {
  106.     var x;
  107.     var y;
  108.     x = 0;
  109.     y = 0;
  110.  
  111.     var elem = document.all[el_name];
  112.     do 
  113.     {
  114.         x += elem.offsetLeft;
  115.         y += elem.offsetTop;
  116.         if (elem.tagName == "BODY")
  117.             break;
  118.         elem = elem.offsetParent; 
  119.     } while  (1 > 0);
  120.  
  121.     shift[0] = x;
  122.     shift[1] = y;
  123.     return  x;
  124. }    
  125.  
  126. function SetCalendarOnElement(el_name)
  127. {
  128.     if (el_name=="") 
  129.     el_name = element_id;
  130.     var shift = new Array(2);
  131.     GetBodyOffsetX(el_name, shift);
  132.     document.all.calendar.style.pixelLeft  = shift[0]; //  - document.all.calendar.offsetLeft;
  133.     document.all.calendar.style.pixelTop = shift[1] + 25 ;
  134. }
  135.  
  136.  
  137.  
  138. function ShowCalendar(elem_name)
  139. {
  140.         if (elem_name=="")
  141.         elem_name = element_id;
  142.  
  143.         element_id    = elem_name; // element_id is global variable
  144.         newCalendar();
  145.         SetCalendarOnElement(element_id);
  146.         //document.all.calendar.style.visibility = "visible";
  147.         document.all.calendar.style.display="inline";
  148. }
  149.  
  150. function HideCalendar()
  151. {
  152.     //document.all.calendar.style.visibility="hidden";
  153.     document.all.calendar.style.display="none";
  154. }
  155.  
  156. function toggleCalendar(elem_name)
  157. {
  158.     //if (document.all.calendar.style.visibility == "hidden")
  159.     if(document.all.calendar.style.display=="none")
  160.         ShowCalendar(elem_name);
  161.     else 
  162.         HideCalendar();
  163. }
  164. -->
  165. </script>
  166.  
  167. <style>
  168. .today {COLOR: black; FONT-FAMILY: sans-serif; FONT-SIZE: 10pt; FONT-WEIGHT: bold}
  169. .days {COLOR: navy; FONT-FAMILY: sans-serif; FONT-SIZE: 10pt; FONT-WEIGHT: bold; TEXT-ALIGN: center}
  170. .dates {COLOR: black; FONT-FAMILY: sans-serif; FONT-SIZE: 10pt}
  171. </style>
  172.  
  173.  
  174. </head>
  175. <body>
  176. <FORM name=myForm>
  177. <INPUT id=MyDate name=MyDate size=15> 
  178. <a href="javascript:;" onClick="toggleCalendar('MyDate')">Calendar</a>
  179. </form>
  180.  
  181.  
  182. <TABLE bgColor=#ffffff border=1 cellPadding=0 cellSpacing=3 id=calendar style="DISPLAY: none; POSITION: absolute; Z-INDEX: 4">
  183.   <TBODY>
  184.   <TR>
  185.     <TD colSpan=7 vAlign=center>
  186.     <!-- Month combo box -->
  187.     <SELECT id=month onchange=newCalendar()> 
  188.         <SCRIPT language=JavaScript>
  189.         // Output months into the document.
  190.         // Select current month.
  191.         for (var intLoop = 0; intLoop < months.length; intLoop++)
  192.             document.write("<OPTION " +    (today.month == intLoop ? "Selected" : "") + ">" + months[intLoop]);
  193.         </SCRIPT>
  194.     </SELECT> 
  195.     <!-- Year combo box -->
  196.     <SELECT id=year onchange=newCalendar()> 
  197.         <SCRIPT language=JavaScript>
  198.         // Output years into the document.
  199.         // Select current year.
  200.         for (var intLoop = 1900; intLoop < 2028; intLoop++)
  201.             document.write("<OPTION " + (today.year == intLoop ? "Selected" : "") + ">" + intLoop);
  202.         </SCRIPT>
  203.     </SELECT> 
  204.  
  205.     </TD>
  206.   </TR>
  207.  
  208.  
  209.  
  210.   <TR class=days>
  211.     <!-- Generate column for each day. -->
  212.     <SCRIPT language=JavaScript>
  213.     // Output days.
  214.     for (var intLoop = 0; intLoop < days.length; intLoop++)
  215.         document.write("<TD>" + days[intLoop] + "</TD>");
  216.     </SCRIPT>
  217.   </TR>
  218.  
  219.  
  220.   <TBODY class=dates id=dayList onclick="getDate('')" vAlign=center>
  221.   <!-- Generate grid for individual days. -->
  222.   <SCRIPT language=JavaScript>
  223.     for (var intWeeks = 0; intWeeks < 6; intWeeks++)
  224.     {
  225.         document.write("<TR>");
  226.         for (var intDays = 0; intDays < days.length; intDays++)
  227.             document.write("<TD></TD>");
  228.         document.write("</TR>");
  229.     }
  230.   </SCRIPT>
  231.  
  232.   <!-- Generate today day. --></TBODY>
  233.   <TBODY>
  234.   <TR>
  235.     <TD class=today colSpan=5 id=todayday onclick=getTodayDay()></TD>
  236.     <TD align=right colSpan=2><A href="javascript:HideCalendar();"><SPAN style="COLOR: black; FONT-SIZE: 10px"><B>Hide</B></SPAN></A></TD>
  237.   </TR>
  238.   </TBODY>
  239.  
  240. </TABLE>
  241.  
  242. </body>
  243. </html>
  244.  
  245.  
  246.  
Jun 29 '09 #1
1 3811
acoder
16,027 Expert Mod 8TB
The code is very IE-specific. Just by a cursory glance, I noticed:
1. document.all
2. innerText
3. global window.event
4. srcElement

All non-standard and will not work in most browsers. Since you've got this for free online, scrap this code - it's not worth the effort changing it - and get a decent cross-browser calendar. I suggest you try Dynarch.
Jun 29 '09 #2

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

Similar topics

25
by: delerious | last post by:
I see some code examples like this: <DIV onmouseover="this.style.background='blue'"> and other code examples like this: <DIV onmouseover="javascript:this.style.background='blue'"> Which...
6
by: Andy Fish | last post by:
Hi, I want to use an anchor tag to invoke some javascript and I've read that it's bad form to use <a href="javascript:foo()"> I've read endless usenet posts and hint sites on the net, they all...
9
by: MStepansky | last post by:
Whats the difference between Javascript and Java3D? I mean can Javascript do like Java3D can? Or is Java3D on top of Javascript (the core, if thats what it is)? Then I should learn Javascript...
14
by: tshad | last post by:
I posted this on the asp.net group, also. I wasn't sure whether this was an asp.net problem or a javascript problem. I have a page that was originally created from a program I found on the net...
1
by: IkBenHet | last post by:
Hello, I found this script to create a simple rich text form (http://programmabilities.com/xml/index.php?id=17): <html> <head> <title>Rich Text Editor</title> </head> <body>
9
by: tshad | last post by:
This is from my previous post, but a different issue. I have the following Javascript routine that opens a popup page, but doesn't seem to work if called from an asp.net button. It seems to work...
14
by: Rich | last post by:
I am converting my enterprise solution from VS 2003 (.NET v1.1.4322) to VS 2005 (.NET v2.0.50727). The entire solution uses serveral technologies - Windows Server 2003 (AD, SQL Server 2000, IIS,...
104
by: Leszek | last post by:
Hi. Is it possible in javascript to operate on an array without knowing how mamy elements it has? What i want to do is sending an array to a script, and this script should add all values from...
2
Frinavale
by: Frinavale | last post by:
JavaScript in ASP.NET Using JavaScript in ASP.NET pages can make your application seem to work faster and prevent unnecessary calls to the server. JavaScript can be used to perform client-side...
0
BarryA
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...
0
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
Oralloy
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.