LeeDJC, on 23 February 2011 - 09:34 AM, said:
Thanks for all the responses above. I managed to get my code to work thanks to you guys.
However, I have one question. I want to get the images to change at half past the hour instead of on the hour. How do I do this? I've tried with the following code, but it doesn't work
However, I have one question. I want to get the images to change at half past the hour instead of on the hour. How do I do this? I've tried with the following code, but it doesn't work
var weekday = ['Sunday','Monday','Tuesday','Wednesday','Thrsday','Friday','Saturday'];
var ImgURL = 'images/';
var ImgList = [
['closed.gif'],
["open.gif"] // Note: no comma at end of list
];
function pixTimeChange() {
var t=new Date();
// See the time below. Note: The time is in 24 hour format.
// In the example here, "7" = 7 AM; "17" =5PM.
var h = t.getHours();
var m = t.getMinutes()
var d = t.getDay();
var el=document.getElementById('myimage');
el.src = ImgURL+ImgList[0];
el.alt = ImgList[0];
switch (d) {
case 1 : // Mon
case 2 : // Tue
case 3 : // Wed
case 4 : // Thu
if ((h >= 16) && (m >=30) && (h < 22) && (m < 30)) { el.src = ImgURL+ImgList[1]; el.alt = ImgList[1]; }
break;
case 5 : // Fri
... code continues ...
Your question is a bit vague.
Why does it not work? Is it the time logic or the display logic?
If the image display, you might try changing the ImgURL = 'images/' statement
to the actual full domain and path
or modify it to ImgURL = './images/' if it is a relative URL.
If the problem is the logic about the minutes, does the following:
case 4 : // Thu
if ((h >= 16) && (m >=30) && (h < 22) && (m < 30)) { el.src = ImgURL+ImgList[1]; el.alt = ImgList[1]; }
break;
mean you are trying to set the image when it is between 4:30pm and 9:30pm?
If that is the intent, then you need to split into two statements as "m" cannot be >= 30 and <30 at the same time as your logic implies.
Try:
if ((h >= 16) && (h < 22)) { // between 4pm and 9pm
// now check for more than or equal to 30 minutes past the hour
if (m >= 30) { el.src = el.src = ImgURL+ImgList[1]; el.alt = ImgList[1]; }
}
As always, the more information you can supply about your problem
the faster for you and the easier for us to make a recommendation as to what to modify.
Good Luck!

New Topic/Question
Reply




MultiQuote



|