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;
if(hours<12)
msg = "Good Morning";
else if(hours<18)
msg = "Good Afternoon";
else
msg = "Good Evening";
return(msg);
}

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.

<html>

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

</body>

</html>

To change the background using Javascript see here

Changed....again