Hi all ,
i got teh below code for a javascript calendar from teh internet. Works great, but I want the dates to be clickable. Also, I want to know how to include an external JS file in this........
please suggest......the 'c' varibale should be clickable..
All suggestions are welcome.
Thanks,
Karthik
<html>
<body>
<script language="JavaScript">
var now = new Date();
var month_array = new Array("january","february"
,"march","
April","Ma
y","June",
"July","Au
gust","Sep
tember","O
ctober","N
ovember","
December")
;
document.write("<form name=date_list><table bgcolor=silver border=0 cellspacing = 0 cellpading = 0><tr><td>");
document.write("<select name=month onchange=change_month(this
.options.s
electedInd
ex)>");
for(i=0;i<month_array.leng
th;i++)
{
if (now.getMonth() != i)
{document.write ("<option value="+i+">"+month_array[
i]);}
else
{document.write ("<option value="+i+" selected>"+month_array[i])
;}
}
document.write("</select>"
);
document.write("</td><td>"
);
document.write ("<select name=year onchange=change_year(this.
options[th
is.options
.selectedI
ndex])>");
for(i=1950;i<3000;i++)
{
if (now.getYear() != i)
{document.write("<option value="+i+">"+i);}
else
{document.write("<option value="+i+" selected>"+i);}
}
document.write("</select><
/td></tr><
tr><td colspan=2><center>");
document.write("<table bgcolor=white border=0 cellspacing = 0 cellpading = 0 width=100%><tr bgcolor=yellowgreen align=center>");
document.write("<td><font color=white>M</font></td><
td><font color=white>T</td><td><fon
t color=white>W</td><td><fon
t color=white>T</td><td><fon
t color=white>F</td><td ><font color=white>S</td><td ><font color=white>S</td>");
document.write("</tr><tr>"
);
for(j=0;j<6;j++)
{
for(i=0;i<7;i++)
{
document.write("<td align=center id=d"+i+"r"+j+"></td>")
}
document.write("</tr>");
}
document.write("</table>")
;
document.write("</center><
/from></td
></tr></ta
ble>");
var show_date = new Date();
function set_cal(show_date)
{
//alert(+show_date.getYear
());
begin_day = new Date (show_date.getYear(),show_
date.getMo
nth(),1);
begin_day_date = begin_day.getDay();
end_day = new Date (show_date.getYear(),show_
date.getMo
nth()+1,1)
;
count_day = (end_day - begin_day)/1000/60/60/24;
input_table(begin_day_date
,count_day
,show_date
.getYear()
,show_date
.getMonth(
));
}
set_cal(show_date);
function input_table(begin,count,ye
ar,month)
{//alert(now.getDate());
init();
j=0;
if (begin!=0){i=begin-1;}else
{i=6}
for (c=1;c<count+1;c++)
{
colum_name = eval("d"+i+"r"+j);
if ((now.getDate() == c)&&(show_date.getMonth() == now.getMonth())&&(show_dat
e.getYear(
) == now.getYear())) {colum_name.style.backgrou
ndColor = "#FF9900";colum_name.style
.color = "white";colum_name.style.l
ink="asd"}
;
colum_name.innerText=c;
i++;
if (i==7){i=0;j++;}
}
}
function init()
{
for(j=0;j<6;j++)
{
for(i=0;i<7;i++)
{
colum_name = eval("d"+i+"r"+j);
colum_name.innerText = "-";
colum_name.style.backgroun
dColor ="";
colum_name.style.color ="";
}
}
}
function change_month(sel_month)
{
show_date = new Date(show_date.getYear(),s
el_month,1
);
set_cal(show_date);
}
function change_year(sel_year)
{
sel_year = sel_year.value;
show_date = new Date(sel_year,show_date.ge
tMonth(),1
);
set_cal(show_date);
}
// End -->
</script>
</body>
</html>
Start Free Trial