|
|||||||
| JavaScript JavaScript (not Java) Discussion and technical support, including AJAX and frameworks (JQuery, MooTools, Prototype...) |
![]() |
|
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#16
|
|||
|
|||
|
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title></title>
<script type="text/javascript">
/*<![CDATA[*/
function CngImg(){
var img;
var ToDay=new Date();
var hour = ToDay.getHours(); //set variable hour to the hour of the day
var day = ToDay.getDay(); //set variable day to the day of the week.
var year = ToDay.getFullYear(); //set variable year to the current year
//G is the date key for hours in 24 format (not 12), with no leading 0s, like 02.
// Adjust 2 hour offset for MST below.
hour = hour-2;
// MONDAY SCHEDULE
if (day == 1){
if (hour < 0) img = 'Three.gif';
else if (hour >= 0 && hour < 18) img = 'One.gif';
else if (hour >= 18 && hour < 20) img = 'One.gif';
else if (hour >= 20 && hour < 22) img = 'One.gif';
else if (hour >= 22) img = 'One.gif';
}
// TUESDAY SCHEDULE
else if (day == 2){
if (hour < 0) img = 'One.gif';
else if (hour >= 0 && hour < 18) img = 'One.gif';
else if (hour >= 18 && hour < 20) img = 'One.gif';
else if (hour >= 20 && hour < 22) img = 'One.gif';
else if (hour >= 22) img = 'Two';
}
// WEDNESDAY SCHEDULE
else if (day == 3){
if (hour < 0) img = 'One.gif';
else if (hour >= 0 && hour < 18) img = 'Three.gif';
else if (hour >= 18 && hour < 20) img = 'Four.gif';
else if (hour >= 20 && hour < 22) img = 'Three.gif';
else if (hour >= 22) img = 'Three.gif';
}
// THURSDAY SCHEDULE
else if (day == 4){
if (hour < 0) img = 'Three.gif';
else if (hour >= 0 && hour < 18) img = 'Five.gif';
else if (hour >= 18 && hour < 20) img = 'Two.gif';
else if (hour >= 20 && hour < 22) img = 'Three.gif';
else if (hour >= 22) img = 'Four.gif';
}
// FRIDAY SCHEDULE
else if (day == 5){
if (hour < 0) img = 'Two';
else if (hour >= 0 && hour < 18) img = 'One.gif';
else if (hour >= 18 && hour < 20) img = 'One.gif';
else if (hour >= 20 && hour < 22) img = 'One.gif';
else if (hour >= 22) img = 'One.gif';
}
// SATURDAY SCHEDULE
else if (day == 6){
if (hour < 0) img = 'One.gif';
else if (hour >= 0 && hour < 2) img = 'One.gif';
else if (hour >= 2 && hour < 4) img = 'One.gif';
else if (hour >= 4 && hour < 16) img = 'One.gif';
else if (hour >= 16 && hour < 18) img = 'One.gif';
else if (hour >= 18 && hour < 20) img = 'One.gif';
else if (hour >= 20 && hour < 22) img = 'One.gif';
else if (hour >= 22) img = 'One.gif';
}
// SUNDAY SCHEDULE
else if (day == 0){
if (hour < 16) img = 'One.gif';
else if (hour >= 16 && hour < 18) img = 'One.gif';
else if (hour >= 18 && hour < 20) img = 'One.gif';
else if (hour >= 20 && hour < 22) img = 'One.gif';
else if (hour >= 22) img = 'One.gif';
}
document.getElementById('MyImage').src='http://www.vicsjavascripts.org.uk/StdImages/'+img;
setInterval(function(){ CngImg(); },1000*60);
}
</script>
</head>
<body onload="CngImg()" >
<img id="MyImage" src="" width="50" height="50" />
</body>
</html>
__________________
Vic God loves you and will never love you less. http://www.vicsjavascripts.org.uk remove any spaces between java & script |
|
#17
|
|||
|
|||
|
Outstanding m8 thanks
I will test it out and let you know how i get on. Next question is...how would i get it to run over a 2 week period as our djs play fortnightly? Would i repeat some of the script and have 14 days instead of 7. |
|
#18
|
|||
|
|||
|
Quote:
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title></title>
<script type="text/javascript">
/*<![CDATA[*/
function CngImg(){
var img;
var ToDay=new Date();
for (var srt,z0=1;z0<31;z0++){
srt=new Date(ToDay.getFullYear(),0,z0);
if (srt.getDay()==0){ // findes the first sunday in january, 1 = monday, 2 = tueseday ........
break;
}
}
var week=Math.floor((ToDay-srt)/1000/60/60/24/7)%2;
var hour = ToDay.getHours(); //set variable hour to the hour of the day
var day = ToDay.getDay(); //set variable day to the day of the week.
var year = ToDay.getFullYear(); //set variable year to the current year
//G is the date key for hours in 24 format (not 12), with no leading 0s, like 02.
// Adjust 2 hour offset for MST below.
hour = hour-2;
if (week==1){ // odd weeks
// MONDAY SCHEDULE
if (day == 1){
if (hour < 0) img = 'Three.gif';
else if (hour >= 0 && hour < 18) img = 'One.gif';
else if (hour >= 18 && hour < 20) img = 'One.gif';
else if (hour >= 20 && hour < 22) img = 'One.gif';
else if (hour >= 22) img = 'One.gif';
}
// TUESDAY SCHEDULE
else if (day == 2){
if (hour < 0) img = 'One.gif';
else if (hour >= 0 && hour < 18) img = 'One.gif';
else if (hour >= 18 && hour < 20) img = 'One.gif';
else if (hour >= 20 && hour < 22) img = 'One.gif';
else if (hour >= 22) img = 'Two';
}
// WEDNESDAY SCHEDULE
else if (day == 3){
if (hour < 0) img = 'One.gif';
else if (hour >= 0 && hour < 18) img = 'Three.gif';
else if (hour >= 18 && hour < 20) img = 'Four.gif';
else if (hour >= 20 && hour < 22) img = 'Three.gif';
else if (hour >= 22) img = 'Three.gif';
}
// THURSDAY SCHEDULE
else if (day == 4){
if (hour < 0) img = 'Three.gif';
else if (hour >= 0 && hour < 18) img = 'Five.gif';
else if (hour >= 18 && hour < 20) img = 'Two.gif';
else if (hour >= 20 && hour < 22) img = 'Three.gif';
else if (hour >= 22) img = 'Four.gif';
}
// FRIDAY SCHEDULE
else if (day == 5){
if (hour < 0) img = 'Two';
else if (hour >= 0 && hour < 18) img = 'One.gif';
else if (hour >= 18 && hour < 20) img = 'One.gif';
else if (hour >= 20 && hour < 22) img = 'One.gif';
else if (hour >= 22) img = 'One.gif';
}
// SATURDAY SCHEDULE
else if (day == 6){
if (hour < 0) img = 'One.gif';
else if (hour >= 0 && hour < 2) img = 'One.gif';
else if (hour >= 2 && hour < 4) img = 'One.gif';
else if (hour >= 4 && hour < 16) img = 'One.gif';
else if (hour >= 16 && hour < 18) img = 'One.gif';
else if (hour >= 18 && hour < 20) img = 'One.gif';
else if (hour >= 20 && hour < 22) img = 'One.gif';
else if (hour >= 22) img = 'One.gif';
}
// SUNDAY SCHEDULE
else if (day == 0){
if (hour < 16) img = 'One.gif';
else if (hour >= 16 && hour < 18) img = 'One.gif';
else if (hour >= 18 && hour < 20) img = 'One.gif';
else if (hour >= 20 && hour < 22) img = 'One.gif';
else if (hour >= 22) img = 'One.gif';
}
}
else {
//even weeks SCHEDULE
}
if (img){
document.getElementById('MyImage').src='http://www.vicsjavascripts.org.uk/StdImages/'+img;
}
setInterval(function(){ CngImg(); },1000*60);
}
</script>
</head>
<body onload="CngImg()" >
<img id="MyImage" src="" width="50" height="50" />
</body>
</html>
__________________
Vic God loves you and will never love you less. http://www.vicsjavascripts.org.uk remove any spaces between java & script Last edited by vwphillips; 11-05-2009 at 11:43 AM. |
|
#19
|
|||
|
|||
|
Thanks m8 very much appreciated!!!
|
|
#20
|
|||
|
|||
|
For some odd reason the script isnt displaying the images, any ideas why m8 have i not set something correctly:-
<script type="text/javascript"> /*<![CDATA[*/ function CngImg(){ var img; var ToDay=new Date(); for (var srt,z0=1;z0<31;z0++){ srt=new Date(ToDay.getFullYear(),0,z0); if (srt.getDay()==0){ // findes the first sunday in january, 1 = monday, 2 = tueseday ........ break; } } var week=Math.floor((ToDay-srt)/1000/60/60/24/7)%2; var hour = ToDay.getHours(); //set variable hour to the hour of the day var day = ToDay.getDay(); //set variable day to the day of the week. var year = ToDay.getFullYear(); //set variable year to the current year //G is the date key for hours in 24 format (not 12), with no leading 0s, like 02. // Adjust 2 hour offset for MST below. hour = hour-2; if (week==1){ // odd weeks // MONDAY SCHEDULE if (day == 1){ if (hour < 0) img = 'images/NPfree.jpg'; else if (hour >= 0 && hour < 18) img = 'images/NPfree.jpg'; else if (hour >= 18 && hour < 20) img = 'images/NPfree.jpg'; else if (hour >= 20 && hour < 22) img = 'images/NPfree.jpg'; else if (hour >= 22) img = 'images/NPfree.jpg'; } // TUESDAY SCHEDULE else if (day == 2){ if (hour < 0) img = 'images/NPfree.jpg'; else if (hour >= 0 && hour < 18) img = 'images/NPfree.jpg'; else if (hour >= 18 && hour < 20) img = 'images/NPfree.jpg'; else if (hour >= 20 && hour < 22) img = 'images/NPfree.jpg'; else if (hour >= 22) img = 'images/NPfree.jpg'; } // WEDNESDAY SCHEDULE else if (day == 3){ if (hour < 0) img = 'images/NPfree.jpg'; else if (hour >= 0 && hour < 18) img = 'images/NPfree.jpg'; else if (hour >= 18 && hour < 20) img = 'images/NPfree.jpg'; else if (hour >= 20 && hour < 22) img = 'images/NPfree.jpg'; else if (hour >= 22) img = 'images/NPfree.jpg'; } // THURSDAY SCHEDULE else if (day == 4){ if (hour < 0) img = 'images/NPfree.jpg'; else if (hour >= 0 && hour < 18) img = 'images/NPfree.jpg'; else if (hour >= 18 && hour < 20) img = 'images/NPfree.jpg'; else if (hour >= 20 && hour < 22) img = 'images/NPfree.jpg'; else if (hour >= 22) img = 'images/NPfree.jpg'; } // FRIDAY SCHEDULE else if (day == 5){ if (hour < 0) img = 'images/NPfree.jpg'; else if (hour >= 0 && hour < 18) img = 'images/NPfree.jpg'; else if (hour >= 18 && hour < 20) img = 'images/NPfree.jpg'; else if (hour >= 20 && hour < 22) img = 'images/NPfree.jpg'; else if (hour >= 22) img = 'images/NPfree.jpg'; } // SATURDAY SCHEDULE else if (day == 6){ if (hour < 0) img = 'images/NPfree.jpg'; else if (hour >= 0 && hour < 2) img = 'images/NPfree.jpg'; else if (hour >= 2 && hour < 4) img = 'images/NPfree.jpg'; else if (hour >= 4 && hour < 16) img = 'images/NPfree.jpg'; else if (hour >= 16 && hour < 18) img = 'images/NPfree.jpg'; else if (hour >= 18 && hour < 20) img = 'images/NPfree.jpg'; else if (hour >= 20 && hour < 22) img = 'images/NPfree.jpg'; else if (hour >= 22) img = 'images/NPfree.jpg'; } // SUNDAY SCHEDULE else if (day == 0){ if (hour < 16) img = 'images/NPfree.jpg'; else if (hour >= 16 && hour < 18) img = 'images/NPfree.jpg'; else if (hour >= 18 && hour < 20) img = 'images/NPfree.jpg'; else if (hour >= 20 && hour < 22) img = 'images/NPfree.jpg'; else if (hour >= 22) img = 'images/NPfree.jpg'; } } else { //even weeks SCHEDULE } if (img){ document.getElementById('MyImage').src='http://www.harddancefm.com/images/'+img; } setInterval(function(){ CngImg(); },1000*60); } </script> <body onload="CngImg()" > <img id="MyImage" src="" width="340" height="110" /> </body> |
|
#21
|
|||
|
|||
|
check out my working example
are you calling the function from the onload event?
__________________
Vic God loves you and will never love you less. http://www.vicsjavascripts.org.uk remove any spaces between java & script |
|
#22
|
|||
|
|||
|
Ive done everything as should be the script is in header section and the onload in in the body section were i want it displayed.....im not getting any errors showing apart from the image not showing.
Would I need to add an image name in the body src of the onload? <body onload="CngImg()" > <img id="MyImage" src="" width="340" height="110" /> </body> Last edited by TheWeedMan; 11-07-2009 at 09:59 AM. |
|
#23
|
|||
|
|||
|
post a link to your page
__________________
Vic God loves you and will never love you less. http://www.vicsjavascripts.org.uk remove any spaces between java & script |
|
#24
|
|||
|
|||
|
Hi vic
I seem to have found my problem, I was getting a conflict from another script I had used so I removed it everything works fine now. Thank you very much for your help, your an asset to this forum!!! ![]() One last question however.....how would I add a second week schedule to the list. Would I just do the following:- else { //even weeks SCHEDULE //Repeat the whole Mon to Sunday schedule list in here? } Last edited by TheWeedMan; 11-07-2009 at 10:39 AM. |
|
#25
|
|||
|
|||
|
Quote:
__________________
Vic God loves you and will never love you less. http://www.vicsjavascripts.org.uk remove any spaces between java & script |
|
#26
|
|||
|
|||
|
Superb....thanks very much for all your help your a godsend!!!.
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|