473,856 Members | 1,708 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

JavaScript-Calender date cant displayed in Mozilla FireFox

38 New Member
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.h tml
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 3854
acoder
16,027 Recognized Expert Moderator MVP
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
3763
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 way is more proper? Or are both ways perfectly fine? Are there any specifications that discuss when "javascript:" should be put in front of code?
6
2540
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 suggest different things and I can't get any kind of consistency, and I can't find any solution that works properly for IE, opera and mozilla. many of the recommended solutions go something like this:
9
2188
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 BEFORE Java3D, right? no? Worse, whats the difference between Java and Javascript? Whats the difference between Visual Basic and Visual Java++? (I still thought Visual Basic is like BASIC programming to allow you to write
14
5505
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 that works well as an html page. It brings up a modal popup window that I have been trying to work out for days now and this was the closest I have been able to come. I added a little asp.net code and an asp.net button and cannot get it to
1
3777
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
4929
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 fine from a link. The button does bring up the popup window, but when I press the links on the page, it doesn't return or close the window. ****************************************************************************
14
25650
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, ASP.NET, ASP.NET Mobile) Windows Mobile 2003 (Pocket IE) I have completed a portion of the conversion (ASP.NET Mobile pages for PIE, and some of the ASP.NET-bases web services), and while testing I have a runtime error that did not exist in the...
104
17036
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 that array Could you show me a little example how to do this? Thanks.
2
37716
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 functionality in the user's browser without having to make calls back to the server; thus, saving resources. The following example demonstrates how you can use an ASP.NET button to trigger a JavaScript call which modifies an ASP.NET TextBox. ...
0
11048
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10692
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10376
tracyyun
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9526
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
7084
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5754
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5954
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4567
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3194
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.