...

View Full Version : Question about Calendars! Please help!



Astillac
06-05-2003, 09:37 AM
I have some script to create a calendar, but I've never really used javascript before, and I don't know how to edit it so I can put more functions in... I have the functions, I just don't know where to put 'em! :rolleyes:

Yeah, so, if anyone reads this is the next hour or so, AIM me, or email with some help, would you? I'd be much obliged.

(I REALLY need to know how to get the function where the user can click on a day and get a pop up window with the date info... It's for a band... Help help help!! Pleeeease.)

Kor
06-05-2003, 09:40 AM
Give us the script to see what can we do :-)

Astillac
06-05-2003, 09:53 AM
Okay, this is the script I have. I have no idea what is what... geh.


<!--
function getmonth(themonth0, themonth1, themonth2, themonth3, themonth4, themonth5, themonth6, themonth7, themonth8, themonth9, themonth10, themonth11)
{
this[0] = themonth0; this[1] = themonth1; this[2] = themonth2;
this[3] = themonth3; this[4] = themonth4; this[5] = themonth5;
this[6] = themonth6; this[7] = themonth7; this[8] = themonth8;
this[9] = themonth9; this[10] = themonth10; this[11] = themonth11;
}
function makecalendar()
{
var whatIsIt = "JanFebMarAprMayJunJulAugSepOctNovDec";
var today = new Date(); var thisDay;
var monthDays = new getmonth(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
year=today.getFullYear(); thisDay = today.getDate();
if (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0))
monthDays[1] = 29; nDays = monthDays[today.getMonth()];
IsitNow = today; IsitNow.setDate(1); FindOut = IsitNow.getDate();
if (FindOut == 2) IsitNow.setDate(0); startDay = IsitNow.getDay();
document.write("<table border=0 bgcolor=black>");
document.write("<tr><td colspan=7 align=center><font color=white><b>");
document.write(whatIsIt.substring(today.getMonth() * 3, (today.getMonth() + 1) * 3));
document.write(" "); document.write(year);
document.write("</b></font></td></tr><tr><td align=center><font color=white><b>Sun</b></font></td><td align=center><font color=white><b>Mon</b></font></td><td align=center><font color=white><b>Tue</b></font></td><td align=center><font color=white><b>Wed</b></font></td><td align=center><font color=white><b>Thu</b></font></td><td align=center><font color=white><b>Fri</b></font></td><td align=center><font color=white><b>Sat</b></font></td></tr>");
document.write("<tr>");
column = 0; for (i=0; i<startDay; i++) {
document.write("<td width=35 bgcolor=black> ");
column++;
}
for (i=1; i<=nDays; i++) {
document.write("</td><td width=35 bgcolor=black><font color=white>");
if (i == thisDay)
document.write("<font color=\"blue>\"><b>")
document.write(i);
if (i == thisDay)
document.write("</b></font>")
column++;
if (column == 7) {
document.write("</td></tr><tr>");
column = 0;
}
}
document.write("</tr></table>");
}
makecalendar();
// -->

Garadon
06-05-2003, 11:05 AM
here this should do it, you need to copy the entire code. the blace u chould put ur click funktion is in bold, I have just put an alert there.



<script>
<!--
function getmonth(themonth0, themonth1, themonth2, themonth3, themonth4, themonth5, themonth6, themonth7, themonth8, themonth9, themonth10, themonth11)
{
this[0] = themonth0; this[1] = themonth1; this[2] = themonth2;
this[3] = themonth3; this[4] = themonth4; this[5] = themonth5;
this[6] = themonth6; this[7] = themonth7; this[8] = themonth8;
this[9] = themonth9; this[10] = themonth10; this[11] = themonth11;
}
function makecalendar()
{
var whatIsIt = "JanFebMarAprMayJunJulAugSepOctNovDec";
var today = new Date(); var thisDay;
var monthDays = new getmonth(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
var month=whatIsIt.substring(today.getMonth() * 3, (today.getMonth() + 1) * 3)
year=today.getFullYear(); thisDay = today.getDate();
if (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0))
monthDays[1] = 29; nDays = monthDays[today.getMonth()];
IsitNow = today; IsitNow.setDate(1); FindOut = IsitNow.getDate();
if (FindOut == 2) IsitNow.setDate(0); startDay = IsitNow.getDay();
document.write("<table border=0 bgcolor=black>");
document.write("<tr><td colspan=7 align=center><font color=white><b>");
document.write(month);
document.write(" "); document.write(year);
document.write("</b></font></td></tr><tr><td align=center><font color=white><b>Sun</b></font></td><td align=center><font color=white><b>Mon</b></font></td><td align=center><font color=white><b>Tue</b></font></td><td align=center><font color=white><b>Wed</b></font></td><td align=center><font color=white><b>Thu</b></font></td><td align=center><font color=white><b>Fri</b></font></td><td align=center><font color=white><b>Sat</b></font></td></tr>");
document.write("<tr>");
column = 0; for (i=0; i<startDay; i++) {
document.write("<td width=35 bgcolor=black> ");
column++;
}
for (i=1; i<=nDays; i++) {
document.write("</td><td width=35 bgcolor=black onClick='alert(\""+i+"-"+month+"\");'><font color=white>");
if (i == thisDay)
document.write("<font color=blue><b>")
document.write(i);
if (i == thisDay)
document.write("</b></font>")
column++;
if (column == 7) {
document.write("</td></tr><tr>");
column = 0;
}
}
document.write("</tr></table>");
}
makecalendar();
</script>

Kor
06-05-2003, 11:12 AM
If i understand well, u wanna click on a date and, on this event, something should happen, ie. a pop up or so

Wel, if u can see, that table and those date are generated by a document.write method, so u can insert there whatever events and call other functions u want.

Unfortunately, the numbers are generated as increments, followinf a "for cicle", so the problem will be a little bit difficult, because you have to insert an "if satement", something like:

for (i=1; i<=nDays; i++) {

//the insertion is below

if (i== 10)
document.write ("<a href=\"#\" onclick=\"javascript:alert(\'bla\')\"> ");
document.write(i);
document.write ("</a>");
//end insertion

The result is that u obtain now a link on the day 10. Onclik appears a n alert, but u can obtain whichever action u need.

You got the ideea? I don't know how much javascript you know, so I don't know if i shoul expand or no those expalantions.

Beware, when insert HTML into document.write("") u have to remember that the genuine " have to be preceeded by /, like this /", so Javascript will know that there have to write it as a string, not as a reserved operator

Kor
06-05-2003, 11:14 AM
sorry, not a backslash. The correct form is \".

Kor
06-05-2003, 12:17 PM
It looks it is not a good position for that insertion, but the principle look fair to me. Somewere is a syntax problem, anyway...:-)

ca_redwards
06-06-2003, 01:15 AM
Originally posted by Astillac
I have some script to create a calendar, but I've never really used javascript before, and I don't know how to edit it so I can put more functions in... I have the functions, I just don't know where to put 'em! :rolleyes:


I don't know if it helps you, but I've created a popup calendar (http://www.angelfire.com/ca/redwards/html__.calendar.html) with less than 4K of JavaScript. If it looks like it might suit your purpose, let me know I may even tailor it for you. :D

:ca_redwards.

Skyzyx
06-06-2003, 03:07 AM
Here's my calendar script:
http://www.skyzyx.com/scripts/calendar.htm

Hope this helps!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum