Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 23
  1. #1
    New to the CF scene
    Join Date
    Apr 2005
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Need help on Conditions

    New to Javascript, and I'd like to get some help with this one. I need a script to display a picture based on day of the week and time of the day. It's for a radio station site that needs to display the pic of the dj on the air at any given time. I'm sure it's a straight-forward script and I assume I would use "if" and "and" conditions, but I'm unsure how to write this out. Basically, "If it's Mon, Tue, Wed, Thur or Fri, and its between 6 and 10 a.m., display "Pic1". If it's (date string again) and between 10 a.m. and 2 p.m. display "Pic2", etc, etc. with different hours for Saturdays and Sundays. Am I on the right track?

    John

  • #2
    Regular Coder
    Join Date
    Oct 2003
    Location
    on a ship
    Posts
    574
    Thanks
    1
    Thanked 6 Times in 5 Posts

    Thumbs up I can help

    well it wont be a short script, but thats because you want to define specific pictures for everyday of the week and then for each day 2 different pics depending on tim of day. I can write it for you if you like. will post it when done.

  • #3
    Regular Coder
    Join Date
    Oct 2003
    Location
    on a ship
    Posts
    574
    Thanks
    1
    Thanked 6 Times in 5 Posts

    need to know a few things

    how many different djs are there each day? and waht are the shift hours?

  • #4
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,075
    Thanks
    0
    Thanked 256 Times in 252 Posts
    It's better if you use server-side language or SSI for this in order to use server date as client-side date settings may be set incorrectly. Imagine if you use client-side time, there would be a chance where a different DJ is displayed because the user's date is wrong or in a different timezone.
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #5
    New to the CF scene
    Join Date
    Apr 2005
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Brandon---

    If you want to take a shot at it, it would be appreciated. I'm a quick learner, so this will help me enormously.

    Monday through Sunday Midnight to 6 a.m. "Pic1",

    Monday through Friday 6-10 a.m. "Pic 2", 10-2 p.m., "Pic3", 2-7 p.m. "Pic4", 7-Midnight "Pic5".

    Saturday 6-10 a.m. "Pic6", 10-2 p.m. "Pic7", 2-7 p.m. 'Pic8", 7-Miidnight "Pic9".....

    There are more, but once you get me started, I can add on as needed. Yeah, it's probably long, but as I said, it seems fairly straight forward. I would appreciated help getting started.

  • #6
    New to the CF scene
    Join Date
    Apr 2005
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Glenngv---

    Although I've done little if anything with server side apps, you're point has occured to me. Can you get me headed in the right direction if I decided that may the best (or just because I'm ghetting adddicted to this programming thing!)

    John

  • #7
    Senior Coder
    Join Date
    Apr 2005
    Posts
    1,051
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Althou this does not take into consideration the day of the week, it does however account for the timezone you are in. With a few small mods it can also check the day of the week.

    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <title>Untitled Document</title>
    <script>
    /* When you are building the image array take note at the
    element number.. we will be using this to define the 'DJ' */
    var image= new Array(4)
    image[0]= 'http://www.codingforums.com/images/icons/icon8.gif';
    image[1]= 'http://www.codingforums.com/images/icons/icon9.gif';
    image[2]= 'http://www.codingforums.com/images/icons/icon6.gif';
    image[3]= 'http://www.codingforums.com/images/icons/icon7.gif';
    /* load images by hour note:: hour 7 = 8am /
    / because we only return the hour it will remain on the image untill 7:59am 
    NOTE:: i have not tested these times... you may have to alter these if statements.
    */
    setTimeout("GetTime()", 1000); // Start Script
    function ChangeImage(hr){
    	if(hr >= 0 && hr <= 7){ // midnight to 8am
    	document.getElementById('djPic').src = image[0];
    	} else if( hr >= 8 && hr <= 15 ){// 8am to 4pm
    	document.getElementById('djPic').src = image[1];
    	} else if( hr >= 16 && hr <= 20 ){// 4pm to 9pm
    	document.getElementById('djPic').src = image[2];
    	} else if( hr >= 21 && hr <= 24 ){// 9pm to midnight
    	document.getElementById('djPic').src = image[3];
    	}
    }
    /*  the section (gmt + (24-5) should be altered to fit your timezone. i.e *-5* = est */
    function GetTime() { 
    var dt = new Date();
    var def = dt.getTimezoneOffset()/60;
    var gmt = (dt.getHours() + def);
    var hr = check24(((gmt + (24-5)) > 24) ? ((gmt + (24-5)) - 24) : (gmt + (24-5)));
    ChangeImage(hr);
    setTimeout("GetTime()", 1000);
    }
    
    function check24(hour) {
    return (hour >= 24) ? hour - 24 : hour;
    }
    </script>
    </head>
    <body>
    <img src="http://www.codingforums.com/images/icons/icon4.gif" id="djPic">
    </body>
    </html>

    EDIT::
    OK, i've found the first problem with this script.
    It does not account for daylight savings.

    I.E Right now (because GMT does not follow dls) the difference between gmt and est is -4 not -5..
    Last edited by rlemon; 04-12-2005 at 04:13 PM.

  • #8
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,075
    Thanks
    0
    Thanked 256 Times in 252 Posts
    Quote Originally Posted by JohnStevenson
    Glenngv---

    Although I've done little if anything with server side apps, you're point has occured to me. Can you get me headed in the right direction if I decided that may the best (or just because I'm ghetting adddicted to this programming thing!)

    John
    What server-side language your host supports?
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #9
    New to the CF scene
    Join Date
    Apr 2005
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Gelnngv--

    CGI, Perl, PHP, possibly more.

    John

  • #10
    Senior Coder
    Join Date
    Apr 2005
    Posts
    1,051
    Thanks
    0
    Thanked 0 Times in 0 Posts
    John,
    So let me get this straight,

    you want an app that will cycle through images dependant on the current time in your timezone.

    Also, the time in which these images will change (and the image itself) will be dependant on the day of the week?

    any other factors in this that may come into play?

    EDIT:::
    I read your above post. Give me a few minutes and i'l post the script.

  • #11
    New to the CF scene
    Join Date
    Apr 2005
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    rlemon--

    I look forward to seeing it! Many Thanks!

    John

  • #12
    Senior Coder
    Join Date
    Apr 2005
    Posts
    1,051
    Thanks
    0
    Thanked 0 Times in 0 Posts
    did you try my other script (the one posted above?)

  • #13
    Senior Coder
    Join Date
    Apr 2005
    Posts
    1,051
    Thanks
    0
    Thanked 0 Times in 0 Posts
    ahh well, here it is folks. works fine for me.

    Takes into account the timezone offset, and displays different images per day.
    Fully commented (altho i do not know how well), and I can awnser any questions you may have about it.

    NOTE> THIS DOES NOT ACCOUNT FOR DLS(Daylight Savings) and you will have to manually adjust your timezone settings to compensate for this.

    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <title>Untitled Document</title>
    <script>
    /* When you are building the image array take note at the
    element number.. we will be using this to define the 'DJ' image 
    */
    var image= new Array(9) //YOU WILL NEED TO ALTER THIS FOR YOUR SPECIFIC IMAGES
    image[0]= 'http://www.codingforums.com/images/icons/icon9.gif';
    image[1]= 'http://www.codingforums.com/images/icons/icon8.gif';
    image[2]= 'http://www.codingforums.com/images/icons/icon7.gif';
    image[3]= 'http://www.codingforums.com/images/icons/icon6.gif';
    image[4]= 'http://www.codingforums.com/images/icons/icon5.gif';
    image[5]= 'http://www.codingforums.com/images/icons/icon4.gif';
    image[6]= 'http://www.codingforums.com/images/icons/icon3.gif';
    image[7]= 'http://www.codingforums.com/images/icons/icon2.gif';
    image[8]= 'http://www.codingforums.com/images/icons/icon1.gif';
    
    setTimeout("GetTime()", 1000); // Start Script
    
    /* load images by hour note::
    //////////////////////////////////
    0 = 1:00:00 (1am to 1:59am)
    1 = 2:00:00 (2am to 2:59am)
    2 = 3:00:00 (3am to 3:59am)
    3 = 4:00:00 (4am to 4:59am)
    4 = 5:00:00 (5am to 5:59am)
    5 = 6:00:00 (6am to 6:59am)
    6 = 7:00:00 (7am to 7:59am)
    7 = 8:00:00 (8am to 8:59am)
    8 = 9:00:00 (9am to 9:59am)
    9 = 10:00:00 (10am to 10:59am)
    10 = 11:00:00 (11am to 11:59am)
    11 = 12:00:00 (12noon to 12:59pm)
    12 = 13:00:00 (1pm to 1:59pm)
    13 = 14:00:00 (2pm to 2:59pm)
    14 = 15:00:00 (3pm to 3:59pm)
    15 = 16:00:00 (4pm to 4:59pm)
    16 = 17:00:00 (5pm to 5:59pm)
    17 = 18:00:00 (6pm to 6:59pm)
    18 = 19:00:00 (7pm to 7:59pm)
    19 = 20:00:00 (8pm to 8:59pm)
    20 = 21:00:00 (9pm to 9:59pm)
    21 = 22:00:00 (10pm to 10:59pm)
    22 = 23:00:00 (11pm to 11:59pm)
    23 = 24:00:00 (12am to 12:59am)
    ///////////////////////////////////
    */
    function getImage(hr, day){ // set if statements. YOU WILL NEED TO ALTER THIS FOR YOUR SPECIFIC IMAGES
    	if(day == 0){ // sunday
    		if((hr >= 23 ) && (hr <= 4)){ // midnight to 6am
    			document.getElementById('djPic').src = image[0];
    		} else if((hr >= 5) && (hr <=8)){ // 6am to 10am
    			document.getElementById('djPic').src = image[1];
    		} else if((hr >= 9) && (hr <= 12)){ // 10am to 2pm
    			document.getElementById('djPic').src = image[2];
    		} else if((hr >= 13) && (hr <=17)){ // 2pm to 7pm
    			document.getElementById('djPic').src = image[6];
    		} else if((hr >= 18) && (hr <= 22)){ // 7pm to midnight
    			document.getElementById('djPic').src = image[8];
    		}
    	} else if(day == 1){ // monday
    		if((hr >= 23 ) && (hr <= 4)){ // midnight to 6am
    			document.getElementById('djPic').src = image[0];
    		} else if((hr >= 5) && (hr <=8)){ // 6am to 10am
    			document.getElementById('djPic').src = image[1];
    		} else if((hr >= 9) && (hr <= 12)){ // 10am to 2pm
    			document.getElementById('djPic').src = image[2];
    		} else if((hr >= 13) && (hr <=17)){ // 2pm to 7pm
    			document.getElementById('djPic').src = image[6];
    		} else if((hr >= 18) && (hr <= 22)){ // 7pm to midnight
    			document.getElementById('djPic').src = image[8];
    		}
    	} else if(day == 2){ // tuesday
    		if((hr >= 23 ) && (hr <= 4)){ // midnight to 6am
    			document.getElementById('djPic').src = image[0];
    		} else if((hr >= 5) && (hr <=8)){ // 6am to 10am
    			document.getElementById('djPic').src = image[1];
    		} else if((hr >= 9) && (hr <= 12)){ // 10am to 2pm
    			document.getElementById('djPic').src = image[2];
    		} else if((hr >= 13) && (hr <=17)){ // 2pm to 7pm
    			document.getElementById('djPic').src = image[6];
    		} else if((hr >= 18) && (hr <= 22)){ // 7pm to midnight
    			document.getElementById('djPic').src = image[8];
    		}
    	} else if(day == 3){ // wednesday
    		if((hr >= 23 ) && (hr <= 4)){ // midnight to 6am
    			document.getElementById('djPic').src = image[0];
    		} else if((hr >= 5) && (hr <=8)){ // 6am to 10am
    			document.getElementById('djPic').src = image[1];
    		} else if((hr >= 9) && (hr <= 12)){ // 10am to 2pm
    			document.getElementById('djPic').src = image[2];
    		} else if((hr >= 13) && (hr <=17)){ // 2pm to 7pm
    			document.getElementById('djPic').src = image[6];
    		} else if((hr >= 18) && (hr <= 22)){ // 7pm to midnight
    			document.getElementById('djPic').src = image[8];
    		}
    	} else if(day == 4){ // thursday
    		if((hr >= 23 ) && (hr <= 4)){ // midnight to 6am
    			document.getElementById('djPic').src = image[0];
    		} else if((hr >= 5) && (hr <=8)){ // 6am to 10am
    			document.getElementById('djPic').src = image[1];
    		} else if((hr >= 9) && (hr <= 12)){ // 10am to 2pm
    			document.getElementById('djPic').src = image[2];
    		} else if((hr >= 13) && (hr <=17)){ // 2pm to 7pm
    			document.getElementById('djPic').src = image[6];
    		} else if((hr >= 18) && (hr <= 22)){ // 7pm to midnight
    			document.getElementById('djPic').src = image[8];
    		}
    	} else if(day == 5){ // friday
    		if((hr >= 23 ) && (hr <= 4)){ // midnight to 6am
    			document.getElementById('djPic').src = image[0];
    		} else if((hr >= 5) && (hr <=8)){ // 6am to 10am
    			document.getElementById('djPic').src = image[1];
    		} else if((hr >= 9) && (hr <= 12)){ // 10am to 2pm
    			document.getElementById('djPic').src = image[2];
    		} else if((hr >= 13) && (hr <=17)){ // 2pm to 7pm
    			document.getElementById('djPic').src = image[6];
    		} else if((hr >= 18) && (hr <= 22)){ // 7pm to midnight
    			document.getElementById('djPic').src = image[8];
    		}
    	} else if(day == 6){ // saturday
    		if((hr >= 23 ) && (hr <= 4)){ // midnight to 6am
    			document.getElementById('djPic').src = image[0];
    		} else if((hr >= 5) && (hr <=8)){ // 6am to 10am
    			document.getElementById('djPic').src = image[1];
    		} else if((hr >= 9) && (hr <= 12)){ // 10am to 2pm
    			document.getElementById('djPic').src = image[2];
    		} else if((hr >= 13) && (hr <=17)){ // 2pm to 7pm
    			document.getElementById('djPic').src = image[6];
    		} else if((hr >= 18) && (hr <= 22)){ // 7pm to midnight
    			document.getElementById('djPic').src = image[8];
    		}
    	}
    }
    
    function GetTime() { 
    var dt = new Date();
    var day = dt.getDay();// 0 = sunday, 1 = monday....... 6 = saturday
    var def = dt.getTimezoneOffset()/60;
    var gmt = (dt.getHours() + def);
    var hr = check24(((gmt + (24-5)) > 24) ? ((gmt + (24-5)) - 24) : (gmt + (24-5))); //(gmt +(24-5)) defines the timezone. (gmt +(24-5)) is EST, (gmt +(24-4)) is EDT
    getImage(hr, day); 
    setTimeout("GetTime()", 1000);
    }
    
    function check24(hour) {
    return (hour >= 24) ? hour - 24 : hour;
    }
    </script>
    </head>
    <body>
    <img src="http://www.codingforums.com/images/icons/icon4.gif" id="djPic">
    </body>
    </html>

  • #14
    New to the CF scene
    Join Date
    Jun 2005
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Help me please

    Hi there, ilive in Portugal, i have a problem: Where i put my timezone? And if its possible cant tell my timezone, please!!

    function GetTime() {
    var dt = new Date();
    var day = dt.getDay();// 0 = sunday, 1 = monday....... 6 = saturday
    var def = dt.getTimezoneOffset()/60;
    var gmt = (dt.getHours() + def);
    var hr = check24(((gmt + (0-1)) > 24) ? ((gmt + (24-5)) - 24) : (gmt + (24-5))); //(gmt +(24-1)) defines the timezone. (gmt +(24-5)) is EST, (gmt +(24-4)) is EDT
    getImage(hr, day);
    setTimeout("GetTime()", 1000);
    }

    function check24(hour) {
    return (hour >= 24) ? hour - 24 : hour;

  • #15
    Senior Coder
    Join Date
    Apr 2005
    Posts
    1,051
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by telefonia
    Hi there, ilive in Portugal, i have a problem: Where i put my timezone? And if its possible cant tell my timezone, please!!

    function GetTime() {
    var dt = new Date();
    var day = dt.getDay();// 0 = sunday, 1 = monday....... 6 = saturday
    var def = dt.getTimezoneOffset()/60;
    var gmt = (dt.getHours() + def);
    var hr = check24(((gmt + (0-1)) > 24) ? ((gmt + (24-5)) - 24) : (gmt + (24-5))); //(gmt +(24-1)) defines the timezone. (gmt +(24-5)) is EST, (gmt +(24-4)) is EDT
    getImage(hr, day);
    setTimeout("GetTime()", 1000);
    }

    function check24(hour) {
    return (hour >= 24) ? hour - 24 : hour;
    edit the text i blod'd with your timezone. i don't know portugals. +- ??
    public string ConjunctionJunction(string words, string phrases, string clauses)
    {
    return (String)(words + phrases + clauses);
    }
    <--- Was I Helpfull? Let me know ---<


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •