Urgent help in Javascript calendar display |
cloudymegz 01-08-2006, 08:21 AM hi,
I need a urgent help..as i am stuck in this calendar javascript code. The below code generate a 12 months calendar. I know how to reduce the number of months etc but want to have a next and previous button which will display the next month. I am not able to put a next and prev month. I need to display only one month and then next or prev month is displayed by clicking on the buttons.
Please help me.
Thanks in advance
PS. code is attached
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#FFFFFF">
<b> Current availability calendar:
<script language=JavaScript1.2 type=text/javascript>
<!--
var apartmentin="mosman";
//-->
</script>
<table dir=ltr cellspacing=1 cellpadding=1 width="100%"
border=0>
<tbody>
<tr>
<td valign=top><!--availCal_start-->
<script language=JavaScript1.2 type=text/javascript>
var apartment = apartmentin;
//Specify bgcolor of calendar
var bg="#F0EEEF"
//Specify font size
var fs=1
// table height
var tbh = 0 // 200
// table width
var tbw = 0 // 150
// cell width
var wd=10 // 22
// cell height
var ht=10 // 22
// border
var bd = 0 // 1
// available cell background
acbg = " bgcolor=#C37C50 "
// unavailable cell background
ucbg = " bgcolor=#F6A472 "
var flg = 0;
//var fs = 1;
M = new Array("January","February","March","April","May","June","July","August","September","October","November","December");
D = new Array("Sun","Mon","Tue","Wed","Thu","Fri","Sat");
function setAvailability()
{
pdy = new Date(); // today
pmo = pdy.getMonth(); // present month
pyr = pdy.getFullYear(); // present year
var j = 0;
for (var i=0; i < 12; i++)
{
if (j == 0)
document.write('<TABLE BORDER=1><TR><TD VALIGN=TOP>');
document.write('');
yr = (pmo==12?pyr+1:pyr); // month's year
mo = (pmo==12?0:pmo); // month
bgn = new Date(M[mo]+" 1,"+yr); // assign to date
Calendar(); // Send month to screen
if (j == 3)
{
document.write('</TD></TR></TABLE>');
j = 0;
}
else
{
document.write('</TD><TD VALIGN=TOP>');
j++;
}
pmo++;
if (pmo == 12)
{
pmo= 0;
pyr++;
}
}
document.write('</TD></TR></TABLE>'); // Finish up
}
function Calendar()
{
var rows = 0;
calendar = 1;
dy = bgn.getDay();
yr = eval(yr);
d = "312831303130313130313031";
if (yr / 4 == Math.floor(yr / 4))
{
d = d.substring(0, 2) + "29" + d.substring(4, d.length);
}
pos = (mo * 2);
ld = eval(d.substring(pos, pos + 2));
document.write("<TABLE BORDER=" + bd + " cellspacing=0" + " style=border-collapse: collapse"
+ " HEIGHT=" + tbh + " WIDTH=" + tbw
+ " BGCOLOR='" + bg
+ "'><TR><TD ALIGN=CENTER COLSPAN=7>"
+ "<FONT SIZE=" + fs + ">" + M[mo] + " " + yr
+ "</FONT></TD></TR><TR><TR>");
rows++;
for (var i = 0;i < 7;i ++)
{
document.write("<TD ALIGN=CENTER WIDTH=" + wd + " HEIGHT=" + ht + ">"
+"<FONT SIZE="+fs+">" + D[i] + "</FONT></TD>");
}
document.write("</TR><TR>");
rows++
ctr = 0;
for (var i = 0;i < 7; i++)
{
if (i < dy)
{
document.write("<TD ALIGN=CENTER WIDTH=" + wd + " HEIGHT=" + ht + ">"
+"<FONT SIZE=" + fs + "> </FONT>"
+" </TD>");
}
else
{
ctr++;
if (available() == 1)
{
cbg = acbg;
}
else
{
cbg = ucbg;
}
document.write("<TD ALIGN=CENTER WIDTH=" + wd + " HEIGHT=" + ht + cbg + ">"
+ "<FONT SIZE=" + fs + ">" + ctr + "</FONT>"
+ "</TD>");
}
}
document.write("</TR><TR>");
rows++;
while (ctr < ld)
{
for (var i = 0;i < 7; i++)
{
ctr++;
if (ctr > ld)
{
document.write("<TD ALIGN=CENTER WIDTH=" + wd + " HEIGHT=" + ht + ">"
+ " </TD>");
}
else
{
if (available() == 1)
{
cbg = acbg;
}
else
{
cbg = ucbg;
}
document.write("<TD ALIGN=CENTER WIDTH=" + wd + " HEIGHT=" + ht + cbg + ">"
+ "<FONT SIZE=" + fs + ">" + ctr + "</FONT>"
+ "</TD>");
}
}
document.write("</TR><TR>");
rows++;
}
if (rows <= 7)
{
for (var i = 0;i < 7; i++)
{
document.write("<TD ALIGN=CENTER WIDTH=" + wd + " HEIGHT=" + ht + ">"
+ " </TD>");
}
}
document.write("</TR></TABLE>");
}
apartmentArray = new Array("h001","o002","h005","s010","s012","m004","r007","r004","r008","s011","m001","o004","o001","h003","s004","m011","m005","m007","e003","w002","w001","r002","r003","Lady112","v001","Rocklands41","s116","m008","Keats610","Queenvic14","Alison212","a002","c005","b003","Greatwest38","j001","Carillon306","Wellington52","b004");
function available()
{
cd = bgn;
cd.setDate(ctr);
if (apartment == "mosman")
return(available_mosman());
if (apartment == "o002")
return(available_o002());
return(0);
}
function available_mosman()
{
sd = new Date(2006,0,00);
ed = new Date(2006,3,31);
if (cd >= sd & cd < ed)
return(1);
if (cd >= sd & cd <= ed & calendar == 0)
return(1);
sd = new Date(2006,5,21);
ed = new Date(2006,6,06);
if (cd >= sd & cd < ed)
return(1);
if (cd >= sd & cd <= ed & calendar == 0)
return(1);
sd = new Date(2006,6,07);
ed = new Date(2006,6,10);
if (cd >= sd & cd < ed)
return(1);
if (cd >= sd & cd <= ed & calendar == 0)
return(1);
return(0);
}
</script>
<!--availCal_end-->
<script language=JavaScript1.2 type=text/javascript>
setAvailability();
document.write("<table><tr><td " + acbg + ">            </td><td> - available </td></tr></table>");
document.write("<table><tr><td " + ucbg + ">            </td><td> - not available</td></tr></table>");
</script>
</td>
</tr>
</tbody>
</table>
</b>
</body>
</html>
|
|
|
|
|