Thursday, 7 May 2009

Javascript to Change Message Based on the Time of Day

This Javascript function checks the time of day and returns Good Morning, if it's before midday, Good Afternoon, if it's between midday and 6pm and Good Evening if it's after 6pm.

function welcomeMessage()
var now = new Date();
var hours = now.getHours();
var msg;
msg = "Good Morning";
else if(hours<18)
msg = "Good Afternoon";
msg = "Good Evening";

As the date is taken from the client, so it doesn't matter where in the World the user is, they will get the message relevant to them.

Goodbye and

Tuesday, 5 May 2009

PHP to Change Background Based on the Day of the Year

This PHP will change the background image based on the day of the year.

It expects there to be 366 images to change to called 001.jpg, 002.jpg ... 366.jpg.


<body style="background-image: url(<?php echo str_pad(date(z),3,'0'); ?>.jpg)">



To change the background using Javascript see here