Your homework assignment at the end of this chapter will be to figure out how to add seconds to the time.
This is because you have to consider the page loading time.
Sometimes, you might need to automatically update a Web page with dynamic elements.
For example, you would want a poll Web site to update the poll results as soon as its database receives new votes, or you might need a stock Web site that periodically updates real-time trading data of securities.
The poll results and the real-time trading data are dynamic elements that are unknown until run time, but elements that should be added or updated when the server side sends a signal. A previous developer Works article, "Craft Ajax applications using JSF with CSS and Java Script, Part 2: Dynamic JSF forms" explains how to hide and display optional JSF components without refreshing a Web page.
With Java Script you can update the content on your pages automaticallyÂevery day, every hour, or every second.
In this chapter, I'll focus on a simple script that automatically changes the date on your web page.
Along the way you'll learn: Before getting into the nuts and bolts of functions and variables, let's take a look at a couple of examples of web pages that automatically update themselves, starting with the European Space Agency.
As you can see in Figure 2-1, the ESA's home page shows you the current date.
Rather than change the home page every day, the ESA uses Java Script to change the date automatically.
An even more frequently updated page is the home page of the website, which updates the time as well as the date (see Figure 2-2).
You don't have to sit in front of your computer, updating the dates and times on your websites. The ability to write HTML to web pages dynamically is one of Java Script's most powerful features.