Changing Stuff by Time or Day
By using a little JavaScript you can automatically display
text or images by the time of the day, the day of the week,
month or any variation there of.
Soup of the Day
For your project 1 restaurant web site, you might want to display
the daily specials or the "soup of the day".
Here is the Script you can use to do it:
<script language="JavaScript">
///This is where we get the new date and refresh it
mydate = new Date();
///This is where we extract the day out of the date we have
just retrieved
myday = mydate.getDay();
///Change "The soup of the Day" to whatever you want
your text to be.
/// 0=Sunday, 1=Monday, 2=Tuesday etc.
if(myday == 0) document.write("The Soup of the Day is
Leek and Bacon ");
else if(myday == 1) document.write("The Soup of the Day
is Asparagus ");
else if(myday == 2) document.write("The Soup of the Day
is Chicken Noodle ");
else if(myday == 3) document.write("The Soup of the Day
is French Onion ");
else if(myday == 4) document.write("The Soup of the Day
is Vegetable ");
else if(myday == 5) document.write("The Soup of the Day
is Asparagus ");
else if(myday == 6) document.write("The Soup of the Day
is Chicken Noodle ");
</script>
Note: On the example on this page, I added
the <H2></H2> pair inside my quotes. You may format
your text as you please but be careful not to use quotation
marks inside of quotation marks. If you must delineate a string
within your quotation marks use single quotes instead of double
quotes inside your surrounding double quote marks.
Daily Images
Use the same JavaScript as above to have daily images except
add image tags instead of your html. Simply delete the html
between the quote marks and add your image tags <img scr='yourdailyimage.jpg'>.
Here is the code for daily images:
<script language="JavaScript">
///This is where we get the new date and refresh it
mydate = new Date();
///This is where we extract the day out of the date we have
just retrieved
myday = mydate.getDay();
///This is the bit that you should change. 0=Sunday, 1=Monday,
2=Tuesday etc.
///Change Soup of the Day to your image tag <IMG SRC='dailyimage.jpg'>.
if(myday == 0) document.write("<IMG SRC='images/sunday.jpg'>");
else if(myday == 1) document.write("<IMG SRC='images/monday.jpg'>");
else if(myday == 2) document.write("<IMG SRC='images/tuesday.jpg'>");
else if(myday == 3) document.write("<IMG SRC='images/wednesday.jpg'>");
else if(myday == 4) document.write("<IMG SRC='images/thursday.jpg'>");
else if(myday == 5) document.write("<IMG SRC='images/friday.jpg'>");
else if(myday == 6) document.write("<IMG SRC='images/saturday.jpg'>");
</script>
|