Variable text dependant on day of month

  Charlie Babbage 20:48 21 Jan 07
Locked

I want to include some short text in a web page which would vary according to the current day of the month.

What is the easiest way of doing this, particularly as the server click here does not support anything sophisicated like php scripts?!

I realise that I would probably have to set up the text in a table and then lookup that table having found the current day of the month.

Any assistance given would be much appreciated with relevant code!

  RicScott 11:03 22 Jan 07

<SCRIPT LANGUAGE="JavaScript">
<!--
datetoday = new Date();
timenow=datetoday.getTime();
datetoday.setTime(timenow);
thehour = datetoday.getHours();
if (thehour > 18) display = "Evening";
else if (thehour >12) display = "Afternoon";
else display = "Morning";
var greeting = ("Good " + display + "!");
document.write(greeting);
// -->
</script>

This will put a Good Morning, Good Afternoon etc depending on the time of the day...
You can of course swap the good morning etc messages for something else...

  Charlie Babbage 22:59 22 Jan 07

... why does the following only display the text for the 1st day of the month whereas today is the 22nd day at the time of writing? When I first wrote this code I did not start with 'if (daynow=1) but with '(daynow=22) and it worked fine. What I want displayed is a different text depending on the day of the month.

<SCRIPT LANGUAGE="JavaScript">
datetoday= new Date()
daynow=datetoday.getDate()
if (daynow=1) prayer="Please pray for the Churchwardens, Charlie Jones and Michael Swinson. Sidespeople. Also for people in these
residential homes: Kelton Grange, Geel.";
else if (daynow=22) prayer="Please pray for Mission Link: Mark, Shirley, Lisa and Martin Sinclair (OMF) in Phnom Penh, Cambodia and
for homes in these roads: Templemore, Avonmore, Purley Grove, Boxmore Road";
else if (daynow=23) prayer="Please pray for the Local Police, Fire service, Social Serrvices and Businesses in the area. Also for homes in these roads: Kirkmore, Rexmore, Benmore, Cairnmore and
Lammermore";
else if (daynow=24) prayer="Please pray for newly baptised children/adults and their families and the Baptism preparation team. Also for homes in these roads: Erylmore, Lismore, Incemore, Lochmore and Craigmore";
document.write(prayer)
// -->
</script>


Any further assistance would be much appreciated.

  RicScott 21:50 05 Feb 07

try it in ajax:
click here

  Charlie Babbage 09:52 06 Feb 07

... I have not come across ajax before and shall be interested to look at it. I've also borrowed a book on Javascript from the library!

This thread is now locked and can not be replied to.

Surface Pro (2017) vs Surface Pro 4

Where HTML5 is headed next

MacBook Pro v Surface Pro 5