PDA

View Full Version : Displaying different content for each day



mickennedy
08-01-2006, 04:23 PM
Hello all
I'm trying to find code to display different content depending on the day. I'd appreciate any direction. Thanks!

mburt
08-01-2006, 04:27 PM
edit


<html>
<head>
<script>
onload=function() {
var content = new Array("sunday content","monday content","tuesday content","wednesday content","thurday content","friday content","saturday content")
var date = new Date()
var day = date.getDay()
var obj = document.getElementById("output")
obj.innerHTML=content[day]
}
</script>
</head>
<body>
<div id="output"></div>
</body>
</html>

Displays content by the clock on your pc

mickennedy
08-01-2006, 04:41 PM
Perfect! Can the new Array hold html code?

mburt
08-01-2006, 04:44 PM
Yes, but you'll have to use escape characters.

Ex:



var content = new Array("sunday content,"monday content","<font color=\"red\"><i>tuesday content</i></font>","wednesday content","thurday content","friday content","saturday content")


every time you need to use " type a backslash before it, like this: \"

Twey
08-01-2006, 04:55 PM
Simpler:
<script type="text/javascript">
window.onload = function() {
var today = (new Date()).getDay();
for(var i = 1, e; e = document.getElementById("day" + i + "content"); ++i)
if(i - 1 != today) daycontent.style.display = "none";
};
</script>

<div id="day1content">
Sunday's Content
</div>

<div id="day2content">
Monday's Content
</div>

<div id="day3content">
Tuesday's Content
</div>

<!-- ... and so on, to day7content. -->

mburt
08-01-2006, 04:57 PM
Umm.. That won't work in Mozilla