this is an asp page, which is supposed to be opened in a new browser window, it automatically resizes
to a clients resolution, displaying month view with a possibility to pick a date, which is then inserted
into a opener page control (like input type "text" control), whose reference is passed as an argument to
this asp page
code:
cant copy and paste this?
click here for a copy-and-paste friendly version of this code!
**************************************
name: asp date picker
description:this is an asp page, which
is supposed to be opened in a new browse
r window, it automatically resizes to a
clients resolution, displaying month vi
ew with a possibility to pick a date, wh
ich is then inserted into a opener page
control (like input type "text" control)
, whose reference is passed as an argume
nt to this asp page
by: vadim maslov
inputs:2 possible input arguments: dat
e to display month for (if none – today
s month is automatic default) + opener p
age control name: calendar.asp?date=10/1
2/2000&ctl=calendar
returns:none
assumes:none
side effects:code probably needs to be
adjusted if a servers regional settings
are not american
warranty:
code provided by planet source code(tm)
(www.planet-source-code.com) as is, wi
thout warranties as to performance, fitn
ess, merchantability,and any other warra
nty (whether expressed or implied).
terms of agreement:
by using this source code, you agree to
the following terms…
1) you may use this source code in per
sonal projects and may compile it into a
n .exe/.dll/.ocx and distribute it in bi
nary format freely and with no charge.
2) you may not redistribute this sourc
e code (for example to a web site) witho
ut written permission from the original
author.failure to do so is a violation o
f copyright laws.
3) you may link to this code from anot
her website, provided it is not wrapped
in a frame.
4) the author of this code may have re
tained certain additional copyright righ
ts.if so, this is indicated in the autho
rs description.
**************************************
<%@ language=vbscript %>
<%
option explicit
const top_coordinate = 30
dim curdate
dim dayscount
dim lastday
dim firstday
dim i
dim topc
dim leftc
dim tempdate
dim curmonth
dim curyear
dim calhtml
dim pdate
dim curmonthtext
dim rowcount
dim nextmonth
dim prevmonth
dim retcontrol
curdate = request("date")
retcontrol = request("ctl")
if isdate(curdate) then pdate = formatdatetime(curdate, 0)
if curdate = "" then
curdate = now()
else
if isdate(curdate) then curdate = month(curdate) & "/" & day(curdate) & "/" & year
(curdate)
end if
if isdate(curdate) then
curmonth = month(curdate)
curmonthtext = textmonth(curmonth) & "-" & year(curdate)
curyear = year(curdate)
firstday = curmonth & "/" & "01" & "/" & curyear
lastday = dateadd("d", -1, dateadd("m", 1, firstday))
nextmonth = dateadd("m", 1, firstday)
nextmonth = formatdatetime(month(nextmonth) & "/" & day(curdate) & "/" & year
(nextmonth), 0) & _
"&ctl=" & retcontrol
prevmonth = dateadd("m", -1, firstday)
prevmonth = formatdatetime(month(prevmonth) & "/" & day(curdate) & "/" & year
(prevmonth), 0) & _
"&ctl=" & retcontrol
dayscount = cint(day(lastday))
for i = 1 to dayscount
tempdate = curmonth & "/" & i & "/" & curyear
leftc = calcleft(datepart("w", tempdate, vbmonday))
topc = calctop(tempdate)
calhtml = calhtml & _
"<div style=text-align: center; position: absolute; width: 50px; left: "
& leftc & "px; top: " & topc & _
"px; font-family: tahoma, arial; cursor: hand; "
if formatdatetime(tempdate, vbshortdate) = formatdatetime(now,
vbshortdate) then
calhtml = calhtml & "background-color: orange; color: white"
else
calhtml = calhtml & "background-color: #faf0e6; color: black"
end if
if formatdatetime(tempdate, vbshortdate) = formatdatetime(pdate,
vbshortdate) then
calhtml = calhtml & "; border: solid blue 1px"
end if
calhtml = calhtml & " onclick=" & chr(34) & "ondateselected(" & _
fnumber(month(tempdate)) & "/" & fnumber(day(tempdate)) & "/" & year
(tempdate) & _
")" & chr(34) & ">" & day(tempdate) & "</div>" & vbcrlf
next
end if
function fnumber(fnum)
if len(cstr(fnum)) < 2 then
fnumber = "0" & cstr(fnum)
else
fnumber = fnum
end if
end function
function calcleft(wday)
calcleft = ((wday – 1) * 50) + 2
end function
function calctop(wdate)
dim mstartdate
dim mstartweekday
dim drow
mstartdate = month(wdate) & "/" & "01/" & year(wdate)
mstartweekday = datepart("w", mstartdate, vbmonday)
drow = ((mstartweekday + cint(datediff("d", mstartdate, wdate))) \ 7) + 1
if weekday(wdate, vbmonday) = 7 then drow = drow – 1
calctop = ((drow – 1) * 20) + 1 + top_coordinate
if drow > rowcount then rowcount = drow
end function
function textmonth(dmonth)
select case dmonth
case 1: textmonth = "january"
case 2: textmonth = "february"
case 3: textmonth = "march"
case 4: textmonth = "april"
case 5: textmonth = "may"
case 6: textmonth = "june"
case 7: textmonth = "july"
case 8: textmonth = "august"
case 9: textmonth = "september"
case 10: textmonth = "october"
case 11: textmonth = "november"
case 12: textmonth = "december"
end select
end function
%>
<html>
<head>
<title>date picker</title>
<meta name="generator" content="microsoft visual studio 6.0">
<link rel="stylesheet" type="text/css" href="../site_css.css">
<script language="javascript">
function ondateselected(ldate) {
var cobj = eval("opener.window.document." + hostctl.value);
if (cobj != null) {
cobj.value = ldate;
cobj.focus();
}
self.window.close();
}window.open
function initpos() {
curmonth.style.top = (calrows.value * 20) + 30;
window.resizeto(360, parseint(curmonth.style.top, 10) + parseint
(curmonth.clientheight, 10) + 50);
}
</script>
</head>
<body topmargin="0" leftmargin="0" onload="initpos()">
<input type="hidden" id="calrows" name="calrows" value="<%=rowcount%>">
<input type="hidden" id="hostctl" name="hostctl" value="<%=retcontrol%>">
<div style="position: absolute; left: 2px; top: 2px; width: 350px">
<table width="350">
<tr style="background-color: darkblue; color: white">
<td width="50" align="center"><b>mon</b></td>
<td width="50" align="center"><b>tue</b></td>
<td width="50" align="center"><b>wed</b></td>
<td width="50" align="center"><b>thu</b></td>
<td width="50" align="center"><b>fri</b></td>
<td width="50" align="center"><b>sat</b></td>
<td width="50" align="center"><b>sun</b></td>
</tr>
</table>
<%=calhtml%>
</div>
<div id="curmonth" style="position: absolute; left: 2px; width: 350px; text-align: center;">
<table width="350">
<tr style="background-color: black; color: white">
<td width="100"><a href="calendar.asp?date=<%=prevmonth%>">previous</a></td>
<td align="center" width="150"><b><%=curmonthtext%></b></td>
<td width="100" align="right"><a href="calendar.asp?date=<%=nextmonth%
>">next</a></td>
</tr>
</table>
</div>
</body>
</html>
