Home arrow HTML arrow Page 2 - Designing a Web Page Calendar
HTML

Designing a Web Page Calendar


Some web pages, such as news pages, require the user to look at a calendar in order to appreciate the timing of events. This series shows you how to design a calendar for a web page. This is the first part of an eight-part series.

Author Info:
By: Chrysanthus Forcha
Rating: 5 stars5 stars5 stars5 stars5 stars / 2
April 13, 2009
TABLE OF CONTENTS:
  1. · Designing a Web Page Calendar
  2. · Technical Interpretation of the Page
  3. · Our Simple Calendar Layout
  4. · Code for Simple Month Calendar

print this article
SEARCH DEVARTICLES

TOOLS YOU CAN USE

advertisement
Designing a Web Page Calendar - Technical Interpretation of the Page
(Page 2 of 4 )

I use XHTML norms for the design. The basic XHTML page in our project is:


<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/
xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>

<title>Page with Calendar</title>


</head>

<body onclick="removeCal()">


</body>

</html>


The above code has these elements: XML, DOCTYPE, HTML, HEAD and BODY. The components of the calendar will be contained in a DIV element. There will be buttons which, when clicked, cause a calendar to appear. This is the basic content of the BODY element for now, showing the DIV element and one button.


<div id="Cal" onclick="calJustClicked = true;">

</div>

<button type="button" onclick="calJustClicked = true; showCal()">Show Current Month's Calendar</button>


The DIV element has the ID "Cal." The button has the title "Show Current Month's Calendar." It has an onclick event whose meaning we shall see soon.

In this section we shall deal only with the first button. The CSS display property of the calendar (DIV) is given an initial value of "none." Layering is used; when the calendar is to be displayed, it appears in front of every other element. So the DIV element for the calendar is given the absolute value for its CSS position property, and a z-index value of 2; the BODY element is given the absolute value for its position property, and a z-index value of zero. This is the basic code for the CSS:


<style type="text/css">

body {position:absolute; z-index:0}

div#Cal {position:absolute; left:10px; top:30px; display:none; background-color:LemonChiffon; border:2px solid black; z-index:2}

</style>


When the button is clicked, the showCal() function is called. This function changes the value of the CSS display property for the calendar (DIV) to "block." The calendar is displayed as a result. When you click the BODY element, the removeCal() function is called. This function changes the value of the CSS display property of the calendar (DIV) to "none." The calendar disappears. Note that when this property is "none," the calendar (DIV) is off the screen. This is the basic JavaScript; I explain further below:


<script type="text/javascript">

var CalJustClicked = false;


function showCal()

{

document.getElementById('Cal').style.display = "block";

}


function removeCal()

{

if (CalJustClicked == false)

{

document.getElementById('Cal').style.display = "none";

}


//reset the CalJustClicked boolean variable

CalJustClicked = false;

}

</script>



The onclick attribute of the button is:


onclick = "calJustClicked = true; showCal()".


What is the use of the first statement, "calJustClicked = true;"? When you click the BODY element, a function is called to remove the calendar from the screen. When you click the button, another function is called to display the calendar.

Now, when you click the BODY element, only one function is called. However, when you click the button, the BODY element is indirectly clicked. So, two events are triggered. These events oppose one another. The one from the button causes the calendar to be displayed. The one from the BODY, which follows immediately, causes the calendar to be removed. When we click the button, we want only the first event to take effect.

When you click the button, the statement "calJustClicked = true" first sets the calJustClicked global variable to true, indicating that the button has just been clicked. When the opposing function from the BODY is immediately called, it first checks to see if calJustClicked is true, with


if (calJustClicked == false)


If it is true, it does not remove the calendar. However, before the opposing function completes its execution, it resets the calJustClicked variable to false (the default value). In this way, when you next click the body element, the calendar will be removed.

Now when the calendar is displayed, you may need to click it for one reason or another. When you click the calendar, the BODY element will also receive the click (indirectly). In order to prevent the calendar from being removed, the calendar (DIV) has the attribute


onclick="calJustClicked = true;"


This has the same effect as for the "Show Current Month's Calendar" button.


blog comments powered by Disqus
HTML ARTICLES

- HTML5 Boilerplate: Working with jQuery and M...
- HTML5 Boilerplate Introduction
- New API Platform for HTML5
- BBC Adopts HTML 5, Mozilla Addresses Issues
- Advanced Sticky Footers in HTML and CSS
- HTML and CSS Sticky Footers
- Strategy Analytics Predicts HTML5 Phones to ...
- HTML5 Guidelines for Web Developers
- Learning HTML5 Game Programming
- More Engaging CSS3 and HTML Background Effec...
- Engaging HTML and CSS3 Background Effects
- More Web Columns with CSS3 and HTML
- Columns with CSS3 and HTML
- Creating Inline-Block HTML Elements with CSS
- Drag and Drop in HTML5: Parsing Local Files

Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 



© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 2 - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials