Share this Page URL

Chapter 17. The Programmable Page: Addin... > Some JavaScript Examples - Pg. 199

The Programmable Page: Adding JavaScripts to Your Pages 199 You can then apply one of the statements to this variable. Here's how you'd get the current day: d.getDay() Note, too, that after you go to all this trouble, then it becomes relatively easy to display a custom message to the user based on the current time. For example, you might want to add "Good morning!" if the current date and time is before noon. Here's a long script that takes advantage of all this (see jsdate2.htm on the CD in this book). <SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript"> <!-- // Store the date in a variable d = new Date() dateText = "" // Get the current day and convert it to the name of the day dayValue = d.getDay() if (dayValue == 0) dateText += "Sunday" else if (dayValue == 1) dateText += "Monday" else if (dayValue == 2) dateText += "Tuesday" else if (dayValue == 3) dateText += "Wednesday" else if (dayValue == 4) dateText += "Thursday" else if (dayValue == 5) dateText += "Friday" else if (dayValue == 6) dateText += "Saturday"