Ah, it starts with 0!
Any way to make it start with 1?
(I have others who will be populating the images, and I'd like to K.I.S.S.)
And how can I also make this change sequential text files on Monday for virtual SSI includes?
I tried this, but it didn't work. I'm sure I've got something totally wrong:
<script>
function mondayText(){
var n, now= new Date(), d= new Date(now.getFullYear(), 0, 0);
while(d.getDay()!== 1) d.setDate(d.getDate()+1);
n= Math.floor((now-d)/6.048e8);
document.getElementById('mondaytext').src= '/text'+n+'.txt';
}
window.onload=mondayText;
</script>
</head>
You can't use an algorithm to dynamically decide the location of a server-side include as far as I know, but especially if the code is running on the client side (like the JavaScript you're trying to use). I think you need to look at a basic AJAX tutorial and see if you can combine your code to make it fit. I hope that helps.
function loadXMLDoc()
{
var xmlhttp;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{ // Notice the element output here
document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
}
}
// This is where you would likely put your code
// The filename variable is changeable with JavaScript from here
xmlhttp.open("GET","ajax_info.txt",true);
xmlhttp.send();
Sorry, although I'm not at all new to HTML, I am very new to this stuff. I am learning as fast as I can.
That answer left out a lot of pieces. Could you perhaps hold my hand a little? I often learn best by example. If you could give me more (if not the whole) ball of wax, it would help a great deal, and better educate me.
The first thing we need to do is to work out how we define when a week starts and finishes and how we determine which week a particular date is in. The getDay() method returns a value of 0 for Sunday and 6 for Saturday so let's start by defining our week as running from Sunday to Saturday. The 1st January can fall on any day of the week and so not all of the days in that week will be in the current year but we'll consider the week that contains the 1st January to be week one of the current year even though not all of the days in that week are necessarily in the current year. So week one consists of those days between 1st January and the first Saturday on or after that date and the seven days following that make up week two and so on. Once we get to the end of December the last few days of the year will be in week 53 (or possibly 54 if it is a leap year starting on a Saturday).
I wonder about Leap Year 2012 and the fact that days, months, etc. start with zero.
Bookmarks