1 <html style=
"background-color: buttonface; color: buttontext;">
4 <meta http-equiv=
"content-type" content=
"text/xml; charset=utf-8" />
6 <title>Simple calendar setups [popup calendar]
</title>
8 <!-- calendar stylesheet -->
9 <link rel=
"stylesheet" type=
"text/css" media=
"all" href=
"calendar-win2k-cold-1.css" title=
"win2k-cold-1" />
11 <!-- main calendar program -->
12 <script type=
"text/javascript" src=
"calendar.js"></script>
14 <!-- language for the calendar -->
15 <script type=
"text/javascript" src=
"lang/calendar-en.js"></script>
17 <!-- the following script defines the Calendar.setup helper function, which makes
18 adding a calendar a matter of 1 or 2 lines of code. -->
19 <script type=
"text/javascript" src=
"calendar-setup.js"></script>
25 <h2>DHTML Calendar
— for the impatient
</h2>
29 This page lists some common setups for the popup calendar. In
30 order to see how to do any of them please see the source of this
31 page. For each example it's structured like this: there's the
32 <form
> that contains the input field, and following there is
33 the JavaScript snippet that setups that form. An example of
34 <em>flat
</em> calendar is available in
<a
35 href=
"simple-2.html">another page
</a>.
38 The code in this page uses a helper function defined in
39 "calendar-setup.js". With it you can setup the calendar in
40 minutes. If you're not
<em>that
</em> impatient, ;-)
<a
41 href=
"doc/html/reference.html">complete documenation
</a> is
50 <p><b>Basic setup: one input per calendar.
</b> Clicking in the input field
51 activates the calendar. The date format is
"%m/%d/%Y %I:%M %p". The
52 calendar defaults to
"single-click mode".
</p>
54 <p>The example below has been updated to show you how to create
"linked"
55 fields. Basically, when some field is filled with a date, the other
56 is updated so that the difference between them remains one week. The
57 property useful here is
"onUpdate".
</p>
59 <form action=
"#" method=
"get">
60 <input type=
"text" name=
"date" id=
"f_date_a" />
61 <input type=
"text" name=
"date" id=
"f_calcdate" />
64 <script type=
"text/javascript">
65 function catcalc(cal) {
67 var time = date.getTime()
68 // use the _other_ field
69 var field = document.getElementById(
"f_calcdate");
70 if (field == cal.params.inputField) {
71 field = document.getElementById(
"f_date_a");
72 time -= Date.WEEK; // substract one week
74 time += Date.WEEK; // add one week
76 var date2 = new Date(time);
77 field.value = date2.print(
"%Y-%m-%d %H:%M");
80 inputField :
"f_date_a", // id of the input field
81 ifFormat :
"%Y-%m-%d %H:%M", // format of the input field
87 inputField :
"f_calcdate",
88 ifFormat :
"%Y-%m-%d %H:%M",
99 <p><b>Input field with a trigger button.
</b> Clicking the button activates
100 the calendar. Note that this one needs double-click (singleClick parameter
101 is explicitely set to false). Also demonstrates the
"step" parameter
102 introduced in
0.9.6 (show all years in drop-down boxes, instead of every
103 other year as default).
</p>
105 <form action=
"#" method=
"get">
106 <input type=
"text" name=
"date" id=
"f_date_b" /><button type=
"reset" id=
"f_trigger_b">...
</button>
109 <script type=
"text/javascript">
111 inputField :
"f_date_b", // id of the input field
112 ifFormat :
"%m/%d/%Y %I:%M %p", // format of the input field
113 showsTime : true, // will display a time selector
114 button :
"f_trigger_b", // trigger for the calendar (button ID)
115 singleClick : false, // double-click mode
116 step :
1 // show all years in drop-down boxes (instead of every other year as default)
124 <p><b>Input field with a trigger image.
</b> Note that the Calendar.setup
125 function doesn't care if the trigger is a button, image, or anything else.
126 Also in this example we setup a different alignment, just to show how it's
127 done. The input field is read-only (that is set from HTML).
</p>
129 <form action=
"#" method=
"get">
130 <table cellspacing=
"0" cellpadding=
"0" style=
"border-collapse: collapse"><tr>
131 <td><input type=
"text" name=
"date" id=
"f_date_c" readonly=
"1" /></td>
132 <td><img src=
"img.gif" id=
"f_trigger_c" style=
"cursor: pointer; border: 1px solid red;" title=
"Date selector"
133 onmouseover=
"this.style.background='red';" onmouseout=
"this.style.background=''" /></td>
137 <script type=
"text/javascript">
139 inputField :
"f_date_c", // id of the input field
140 ifFormat :
"%B %e, %Y", // format of the input field
141 button :
"f_trigger_c", // trigger for the calendar (button ID)
142 align :
"Tl", // alignment (defaults to
"Bl")
151 <p><b>Hidden field, display area.
</b> The calendar now puts the date into
2
152 elements: one is an input field of type
"hidden"—so that the user
153 can't directly see or modify it
— and one is a
<span
> element in
154 which the date is displayed. Note that if the trigger is not specified the
155 calendar will use the displayArea (or inputField as in the first example).
156 The display area can have it's own format. This is useful if, for instance,
157 we need to store one format in the database (thus pass it in the input
158 field) but we wanna show a friendlier format to the end-user.
</p>
160 <form action=
"#" method=
"get" style=
"visibility: hidden">
161 <input type=
"hidden" name=
"date" id=
"f_date_d" />
165 <span style=
"background-color: #ff8; cursor: default;"
166 onmouseover=
"this.style.backgroundColor='#ff0';"
167 onmouseout=
"this.style.backgroundColor='#ff8';"
169 >Click to open date selector
</span>.
</p>
171 <script type=
"text/javascript">
173 inputField :
"f_date_d", // id of the input field
174 ifFormat :
"%Y/%d/%m", // format of the input field (even if hidden, this format will be honored)
175 displayArea :
"show_d", // ID of the span where the date is to be shown
176 daFormat :
"%A, %B %d, %Y",// format of the displayed date
177 align :
"Tl", // alignment (defaults to
"Bl")
186 <p><b>Hidden field, display area, trigger image.
</b> Very similar to the
187 previous example. The difference is that we also have a trigger image.
</p>
189 <form action=
"#" method=
"get" style=
"visibility: hidden">
190 <input type=
"hidden" name=
"date" id=
"f_date_e" />
193 <p>Your birthday:
<span id=
"show_e">-- not entered --
</span> <img
194 src=
"img.gif" id=
"f_trigger_e" style=
"cursor: pointer; border: 1px solid
195 red;" title=
"Date selector" onmouseover=
"this.style.background='red';"
196 onmouseout=
"this.style.background=''" />.
</p>
198 <script type=
"text/javascript">
200 inputField :
"f_date_e", // id of the input field
201 ifFormat :
"%Y/%d/%m", // format of the input field (even if hidden, this format will be honored)
202 displayArea :
"show_e", // ID of the span where the date is to be shown
203 daFormat :
"%A, %B %d, %Y",// format of the displayed date
204 button :
"f_trigger_e", // trigger button (well, IMG in our case)
205 align :
"Tl", // alignment (defaults to
"Bl")
214 <p><b>Hidden field, display area.
</b> Very much like the previous examples,
215 but we now disable some dates (all weekends, that is, Saturdays and
218 <form action=
"#" method=
"get" style=
"visibility: hidden">
219 <input type=
"hidden" name=
"date" id=
"f_date_f" />
223 <span style=
"background-color: #ff8; cursor: default;"
224 onmouseover=
"this.style.backgroundColor='#ff0';"
225 onmouseout=
"this.style.backgroundColor='#ff8';"
227 >Click to open date selector
</span>.
</p>
229 <script type=
"text/javascript">
231 inputField :
"f_date_f", // id of the input field
232 ifFormat :
"%Y/%d/%m", // format of the input field (even if hidden, this format will be honored)
233 displayArea :
"show_f", // ID of the span where the date is to be shown
234 daFormat :
"%A, %B %d, %Y",// format of the displayed date
235 align :
"Tl", // alignment (defaults to
"Bl")
236 dateStatusFunc : function (date) { // disable weekend days (Saturdays ==
6 and Subdays ==
0)
237 return (date.getDay() ==
6 || date.getDay() ==
0) ? true : false;