For Webmasters
   Example 1.1
1. More Examples
   Example 1.2
   Example 1.3
   Example 1.4
2. Buttons
   Example 2.1
   Example 2.2
   Example 2.3
   Example 2.4
   Example 2.5
   Example 2.6
   Example 2.7
3. JavaScript Calendar
   Example 3.1
   Example 3.2
   Example 3.3
   Example 3.4
   Example 3.5
   Example 3.6
4. Another JS Calendar
   Example 4.1
   Example 4.2
   Example 4.3
   Example 4.4
5. Integration with PHP
   Example 5.1
Appendix A
Appendix B

   Show example

   zip

ru

For Webmasters

2. Buttons

Let's see now how to work with buttons. For example, we need to show the Lives of Saints on May 1, 2008 and April 2, 2009 when we click on the button: Example 2.1.

The top half of HTML is the same as in previous examples - we have references to the loadCalendar.js scrip, Style Sheet and script to manage pop up window. Code for the May button will be:

<button onclick="loadCalendar2(5,1,2008,1,1,3,0,0)">May 1, 2008</button>

First 3 parameters of loadCalendar2 is Month, Day and Year which is May 1, 2008. 4th parameter allows output of today's day in format Gregorian/Julian. 5th parameter allows output of Calendar's header. Then 6th parameter says output only Lives of major Saints in separate paragraphs. 7th parameter disallows output of the Scripture Readings and 8th parameter disallows output of Troparion. Code for April button is:

<button onclick="loadCalendar2(4,2,2009,1,1,3,0,0)">April 2, 2009</button>

In Example 2.2 we can see how to create a button to show today's Lives of Saints and Scripture Readings. Code is:

<button onclick="todayDate()">Today</button>

When you click on the button it calls todayDate function which looks like JavaScipt in  Example 1.2:

<script type="text/Javascript">
function todayDate() {

var today=new Date();
var mm=today.getMonth()+1;
var dd=today.getDate();
var yy=today.getFullYear();
var dt=1;
var hh=1;
var ll=1;
var tt=0;
var ss=1;

loadCalendar2(mm,dd,yy,dt,hh,ll,tt,ss);
}
</script>

 
 
 
// Get today's date
// Get today's month
// Get today's day
// Get today's year
// Output date
// Output header
// Output Lives of Saints
// Do not output Troparion
// Output Daily Scripture Reading
 

Let's do "tomorrow" button. See Example 2.3. In order to do this we need calculate tomorrow's day by adding one day to today. We are going to use the getTime() method to calculate next day. The getTime() method returns the number of milliseconds since midnight of January 1, 1970. In one day we have 24*60*60*1000 milliseconds: 24 hour * 60 minutes * 60 seconds * 1000 milliseconds. Tomorrow's day will be:

var today=new Date(); // Get today's date
var tomorrow = new Date(today.getTime() + 24*60*60*1000); // Get tomorrow date

Now we can write another function tomorrowDate() to calculate and call the calendar:

function tomorrowDate() {

var today=new Date();
var tomorrow = new Date(today.getTime() + 24*60*60*1000);
var mm=tomorrow.getMonth()+1;
var dd=tomorrow.getDate();
var yy=tomorrow.getFullYear();
var dt=1;
var hh=1;
var ll=1;
var tt=0;
var ss=1;

loadCalendar2(mm,dd,yy,dt,hh,ll,tt,ss);
}

 

// Get today's date
// Get tomorrow's date
// Get tomorrow 's month
// Get tomorrow 's day
// Get tomorrow 's year
// Output date
// Output header
// Output Lives of Saints
// Do not output Troparions
// Output Daily Scripture Reading
 

Based on Example 2.3 we can create the "next day" button. See Example 2.4. We need create variable global to both functions todayDate() and nextdayDate():

var currentDay = new Date();

Then at the and of each function we will assign the calculated day to this variable. In todayDate() function it will be:

currentDay = today;

and in nextdayDate() function it will be:

currentDay = next;

The nextdayDate() will be:

function nextdayDate() {

var next = new Date(currentDay.getTime() + 24*60*60*1000);
var mm=next.getMonth()+1;
var dd=next.getDate();
var yy=next.getFullYear();
var dt=1;
var hh=1;
var ll=1;
var tt=0;
var ss=1;

loadCalendar2(mm,dd,yy,dt,hh,ll,tt,ss);

currentDay = next;
}
 



// Get next day date
// Get next month
// Get next day
// Get next year
// Output date
// Output header
// Output Lives of Saints
// Do not output Troparions
// Output Daily Scripture Reading

 

Functions todayDate() and nextdayDate() have common HTML code to call Orthodox Calendar. Let's optimize code in Example 2.5:

<script type="text/Javascript">
var currentDay = new Date(); // Set up current day for today

function callCalendar(x) {
var mm=x.getMonth()+1; // Get today's month
var dd=x.getDate(); // Get today's day
var yy=x.getFullYear(); // Get today's year
var dt=1; // Output date
var hh=1; // Output header
var ll=3; // Output Lives of Saints
var tt=0; // Do not output Troparions
var ss=1; // Output Daily Scripture Reading

loadCalendar2(mm,dd,yy,dt,hh,ll,tt,ss);
}

function todayDate() {
var today=new Date(); // Get today's date
callCalendar(today);
currentDay = today;
}

function nextdayDate() {
var next = new Date(currentDay.getTime() + 24*60*60*1000); // Get next day date
callCalendar(next);
currentDay = next;
}

</script>

Now it is easy to create "previous day" button. We will write another function previousDate() based on nextdayDate(). Just change plus sign to minus and change variable name next to previous:

function previousDate() {
var previous = new Date(currentDay.getTime() - 24*60*60*1000); // Get tomorrow date
callCalendar(previous);
currentDay = previous;
}

Let's add "previous day" button before today day button:

<button onclick="previousDate()">Previous Day</button>

You can see results in Example 2.6 or Example 2.7.

 Previous Chapter: 1. More Examples

Next Chapter: 3. JavaScript Calendar

O Most Holy Trinity, Our God, Glory to Thee!