By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,873 Members | 1,040 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,873 IT Pros & Developers. It's quick & easy.

Calendar problem.

100+
P: 296
Hello,

I have developed a calendar program in Javascript which opens a calendar as a popup window and when a user clicks on a date the date is copied into the parent windows textbox.

The code of the parent window is as follows -->

Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3.     <title>calendar</title>
  4. </head>
  5.  
  6. <body>
  7. <input type="text" name="parent"/>
  8. <a href="javascript:void(0);" onClick=window.open("cal_popup.html");>Click here to open the calendar window</a>
  9. </body>
  10.  
  11. </html>

The code of the popup window is like this -->

Expand|Select|Wrap|Line Numbers
  1. <html>
  2.  
  3. <head>
  4. <title>Calendar</title>
  5. <script language="javascript" type="text/javascript">
  6.  
  7. function post_value(mm,dt,yy){
  8. opener.document.parent.value = mm + "/" + dt + "/" + yy;
  9. self.close();
  10. }
  11.  
  12.  
  13. function gen_cal(prm,chm) {
  14.     myDate = new Date();
  15.  
  16.     var m,d,y;
  17.     if(prm){
  18.     m=prm+chm;
  19.     }
  20.     else{
  21.     m= myDate.getMonth();
  22.     }
  23.  
  24.     d= myDate.getDate(); // Finds today's date
  25.     y= myDate.getFullYear(); // Finds today's year
  26.  
  27.     var string = new Date(y,m,d);
  28.     var newstring = string.toString();
  29.     var string_array = newstring.split(" ");
  30.  
  31.  
  32. //    mn --> Month is calculated to display at the top of the calendar for eg: Jan
  33.     var mn = string_array[1];
  34.  
  35.     //yn--> Year is calculated to display at the top of the calendar for eg: 2007
  36.     var yn = string_array[5];
  37.  
  38.     //no_of_days -->This is to calculate number of days in a month
  39.     var no_of_days;
  40.     if(mn == "Jan" || mn == "Mar" || mn == "May" || mn == "Jul" || mn == "Aug" || mn == "Oct" || mn == "Dec")
  41.         no_of_days = 31;
  42.     if(mn == "Apr" || mn == "Jun" || mn == "Sep" || mn == "Nov")
  43.         no_of_days = 30;
  44.     if(mn == "Feb")
  45.         if(yn % 4 == 0)
  46.         no_of_days = 29;
  47.         else
  48.         no_of_days = 28;
  49.  
  50.     //j--> This will have the week day of the first day of the month
  51.     myArray = new Array("Sun", "Mon", "Tue", "Wed", "Thu","Fri", "Sat");
  52.     myDate1 = new Date(y,m,1);
  53.     var newdate1 = myDate1.toString();
  54.     var string_date = newdate1.split(" ");
  55.     var j = string_date[0];
  56.  
  57.     for(i=0;i<myArray.length;i++) {
  58.         if(myArray[i] == j)
  59.         j=i;
  60.     }
  61.  
  62.     var adj = "<td>&nbsp;</td>";
  63.     for(k=2; k<=j; k++){ // Adjustment of date starting
  64.         adj = adj + "<td>&nbsp;</td>";
  65.     }
  66.  
  67.     // Starting of top line showing name of the days of the week
  68.  
  69.     document.write(" <table border='1' bordercolor='#FFFF00' cellspacing='0' cellpadding='0' align=center><tr><td>");
  70.  
  71.     document.write("<table cellspacing='0' cellpadding='0' align=center width='100' border='1'><td align=center bgcolor='#ffff00'><font size='3' face='Tahoma'> <a href='javascript:gen_cal("+m+",-1);'><</a> </td><td colspan=5 align=center bgcolor='#ffff00'><font size='3' face='Tahoma'>" + mn + yn + "</td><td align=center bgcolor='#ffff00'><font size='3' face='Tahoma'> <a href='javascript:gen_cal("+m+",1);'>></a> </td></tr><tr>");
  72.  
  73.     document.write("<td><font size='3' face='Tahoma'><b>Sun</b></font></td><td><font size='3' face='Tahoma'><b>Mon</b></font></td><td><font size='3' face='Tahoma'><b>Tue</b></font></td><td><font size='3' face='Tahoma'><b>Wed</b></font></td><td><font size='3' face='Tahoma'><b>Thu</b></font></td><td><font size='3' face='Tahoma'><b>Fri</b></font></td><td><font size='3' face='Tahoma'><b>Sat</b></font></td></tr><tr>");
  74.  
  75.     ////// End of the top line showing name of the days of the week//////////
  76.  
  77.     //////// Starting of the days//////////
  78.     var pv;
  79.     for(i=1;i<=no_of_days;i++){
  80.         pv = m + "," + i + "," + yn;
  81.         document.write(adj + "<td valign=top><font size='2' face='Tahoma'><a href='#'onClick='post_value("+pv+");'>" + i + "</a><br>");
  82.         // This will display the date inside the calendar cell
  83.         document.write(" </font></td>");
  84.         adj='';
  85.         j++;
  86.         if(j==7){
  87.             document.write("</tr><tr>");
  88.             j=0;
  89.         }
  90.     }
  91.     document.write("</tr></table></td></tr></table>");
  92. }
  93.  
  94.  
  95. </script>
  96. </head>
  97.  
  98. <body onLoad="javascript:gen_cal();">
  99. </body>
  100. </html>
Please copy them in two files and run in IE .


There are 2 PROBLEMS -->
1.The month navigation is not working .
2. When we click on a date it should get copied inside a textbox which is not happening.

Please help me in solving this as its very urgent.
May 27 '07 #1
Share this Question
Share on Google+
7 Replies


pbmods
Expert 5K+
P: 5,821
Please copy them in two files and run in IE .
If you wanted us to do that, why didn't you just upload your two text files as attachments?
May 28 '07 #2

100+
P: 296
If you wanted us to do that, why didn't you just upload your two text files as attachments?
How to upload files as attachment ?
May 28 '07 #3

acoder
Expert Mod 15k+
P: 16,027
Put your text box inside form tags so you can reference it properly. Also, avoid using names like "parent". You could give it an id instead and use:
Expand|Select|Wrap|Line Numbers
  1. document.getElementById(yourid).value=...
May 28 '07 #4

100+
P: 296
I am facing problem in the below section. Its the NAVIGATION part -->


Expand|Select|Wrap|Line Numbers
  1.     document.write("<table cellspacing='0' cellpadding='0' align=center width='100' border='1'><td align=center bgcolor='#ffff00'><font size='3'> <a href='javascript:gen_cal("+m+",-1);'><</a> </td><td colspan=5 align=center bgcolor='#4444ff'><font size='3' color='white'><b>" + mn + yn + "</b></td><td align=center bgcolor='#ffff00'><font size='3'> <a href='javascript:gen_cal("+m+",1);'>></a> </td></tr><tr>");


Please help.
May 28 '07 #5

100+
P: 296
ok I have uploaded the two files.


cal_popup.html
http://www.megaupload.com/?d=X4ROLHVI


calendar.html
http://www.megaupload.com/?d=P7OP46BY


Please run them in IE and solve the problem.

Only "Navigation" is the problem.
May 29 '07 #6

acoder
Expert Mod 15k+
P: 16,027
What error do you get? Is this problem only in IE or have you not tested on other browsers?
May 29 '07 #7

100+
P: 296
What error do you get? Is this problem only in IE or have you not tested on other browsers?

First please run those files then you will come to know the problem.

Its just a syntax problem of document.write .
May 29 '07 #8

Post your reply

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