www.webdeveloper.com
Recent Articles
  • Finding Slow Running Queries in ASE 15
  • A More Advanced Pie Chart for Analysis Services Data
  • Adobe AIR Programming Unleashed: Working with Windows
  • Performance Testing SQL Server 2008's Change Data Capture Functionality
  • The ABC's of PHP: Introduction to PHP
  • How to Migrate from BasicFiles to SecureFiles Storage
  • Why the Twitter Haters Are Wrong
  • User Personalization with PHP: Beginning the Application
  • Whats in an Oracle Schema?
  • Lighting Enhancement in Photoshop
  •  

    Go Back   WebDeveloper.com > Client-Side Development > JavaScript

    JavaScript JavaScript (not Java) Discussion and technical support, including AJAX and frameworks (JQuery, MooTools, Prototype...)

    Reply
     
    Thread Tools Search this Thread Rate Thread Display Modes
      #16  
    Old 11-05-2009, 07:50 AM
    vwphillips vwphillips is offline
    Registered User
     
    Join Date: Jun 2004
    Location: Portsmouth UK
    Posts: 2,076
    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
    Reply With Quote
      #17  
    Old 11-05-2009, 09:35 AM
    TheWeedMan TheWeedMan is offline
    Registered User
     
    Join Date: Oct 2009
    Posts: 14
    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.
    Reply With Quote
      #18  
    Old 11-05-2009, 11:08 AM
    vwphillips vwphillips is offline
    Registered User
     
    Join Date: Jun 2004
    Location: Portsmouth UK
    Posts: 2,076
    Quote:
    Would i repeat some of the script and have 14 days instead of 7.
    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.
    Reply With Quote
      #19  
    Old 11-05-2009, 12:09 PM
    TheWeedMan TheWeedMan is offline
    Registered User
     
    Join Date: Oct 2009
    Posts: 14
    Thanks m8 very much appreciated!!!
    Reply With Quote
      #20  
    Old 11-06-2009, 10:38 AM
    TheWeedMan TheWeedMan is offline
    Registered User
     
    Join Date: Oct 2009
    Posts: 14
    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>
    Reply With Quote
      #21  
    Old 11-07-2009, 05:31 AM
    vwphillips vwphillips is offline
    Registered User
     
    Join Date: Jun 2004
    Location: Portsmouth UK
    Posts: 2,076
    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
    Reply With Quote
      #22  
    Old 11-07-2009, 09:34 AM
    TheWeedMan TheWeedMan is offline
    Registered User
     
    Join Date: Oct 2009
    Posts: 14
    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.
    Reply With Quote
      #23  
    Old 11-07-2009, 10:17 AM
    vwphillips vwphillips is offline
    Registered User
     
    Join Date: Jun 2004
    Location: Portsmouth UK
    Posts: 2,076
    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
    Reply With Quote
      #24  
    Old 11-07-2009, 10:34 AM
    TheWeedMan TheWeedMan is offline
    Registered User
     
    Join Date: Oct 2009
    Posts: 14
    resolved

    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.
    Reply With Quote
      #25  
    Old 11-07-2009, 11:51 AM
    vwphillips vwphillips is offline
    Registered User
     
    Join Date: Jun 2004
    Location: Portsmouth UK
    Posts: 2,076
    Quote:
    Repeat the whole Mon to Sunday schedule list in here?
    yes
    __________________
    Vic

    God loves you and will never love you less.

    http://www.vicsjavascripts.org.uk
    remove any spaces between java & script
    Reply With Quote
      #26  
    Old 11-07-2009, 12:17 PM
    TheWeedMan TheWeedMan is offline
    Registered User
     
    Join Date: Oct 2009
    Posts: 14
    Superb....thanks very much for all your help your a godsend!!!.
    Reply With Quote
    Reply

    Bookmarks


    Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
     
    Thread Tools Search this Thread
    Search this Thread:

    Advanced Search
    Display Modes Rate This Thread
    Rate This Thread:

    Posting Rules
    You may not post new threads
    You may not post replies
    You may not post attachments
    You may not edit your posts

    BB code is On
    Smilies are On
    [IMG] code is Off
    HTML code is Off
    Forum Jump


    All times are GMT -5. The time now is 05:32 AM.



    Acceptable Use Policy

    internet.comMediabistrojusttechjobs.comGraphics.com

    WebMediaBrands Corporate Info


    Advertise | Newsletters | Feedback | Submit News

    Legal Notices | Licensing | Permissions | Privacy Policy

    Powered by vBulletin® Version 3.7.3
    Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.