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.
Results 1 to 13 of 13
  1. #1
    New Coder
    Join Date
    Apr 2005
    Posts
    27
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation NEED Urget Help With Timer

    Hi,


    Is there a way that i can update something, after 2 weeks, i think we can do this by using timer but i am having a little problem doing that. Can some ont please help!!!!

    Thanks
    Kim
    Last edited by kimstanely; 05-09-2006 at 06:30 PM.

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,308
    Thanks
    203
    Thanked 2,563 Times in 2,541 Posts
    We need more information to give a helpful reply.

    What do you mean "update something after one day". Update what? Every day or just once?

    I am sure that one of our onts will assist you!

  • #3
    New Coder
    Join Date
    Apr 2005
    Posts
    27
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Internet Explorer

    See this peice of code changes an image hyperlink and alt tag after evey 1 seconds i want it to change after evey i day, the problem is that when i close the window evything starts from beginning i dont want it to do that:

    PHP Code:


    <HTML><HEAD>

    <
    SCRIPT LANGUAGE="JavaScript">

    var 
    timer null
    var     counter =0
    function showImage() {
        
    timer=setTimeout("showImage()"10000);
        
    counter++;

        if (
    counter >= pic.length
            
    counter 1;
        
    document.pictures.src pic[counter].src;
        
    elementA=document.getElementById('image2'); 
        
    elementA.setAttribute('alt'alttextArray[counter]);
        var 
    textA summaryArray[counter];
        
    document.getElementById('text').innerHTML textA;
        
    document.getElementById('links').href linkArray[counter];
    }    

    if (
    document.images) {

        
    pic = new Array()

        
    pic[0] = new Image(108108);
        
    pic[0].src "flag_col.jpg";

        
    pic[1] = new Image(108108);
        
    pic[1].src "books_glasses.jpg";

        
    pic[2] = new Image(108108);
        
    pic[2].src "lawyers_steps.jpg";

        
    pic[3] = new Image(108108);
        
    pic[3].src "pen_book.jpg";

        
    pic[4] = new Image(108108);
        
    pic[4].src "scales1.jpg";
        
        
    pic[5] = new Image(108,108);
        
    pic[5].src 'ccs.gif'
        
        
    pic[6] = new Image(108,108);
        
    pic[6].src 'sj_e.gif'
        
    }
    var 
    alttextArray = new Array()
    alttextArray[0] = 'This 1'
    alttextArray[1] = 'This 2'
    alttextArray[2] = 'This 3'
    alttextArray[3] = 'This 4'
    alttextArray[4] = 'This 5'
    alttextArray[5] = 'This 6'
    var summaryArray = new Array()

    summaryArray[0] = 'Lalal    '
    summaryArray[1] = 'a'
    summaryArray[2] = 'b'
    summaryArray[3] = 'c'
    summaryArray[4] = 'd>'
    summaryArray[5] = 'e'
    summaryArray[6] = 'f'

    var linkArray = new Array()
    linkArray[0] = 'www.yahoo.com'
    linkArray[1] = 'www.hotmail.com'
    linkArray[2] = 'www.yahoo.com'
    linkArray[3] = 'www.yahoo.com'
    linkArray[4] = 'www.yahoo.com'
    linkArray[5] = 'www.yahoo.com'
    linkArray[6] = 'www.yahoo.com'

      
    document.write('<td height="65" valign="top" cellpadding="2" border="1">')
      
    document.write('<IMG SRC="flag_col.jpg" WIDTH="108" HEIGHT="108" NAME="pictures" id="image2" alt="What">');  
      
    document.write('</td>')
      
    document.write('<p>')
      
    document.write('<a href="" id="links">')
      
    document.write('<div id="text">  </div>')
      
    document.write('</a>');

    // - End of JavaScript - -->
    </SCRIPT>
    </HEAD>

    <BODY BACKGROUND="FFFFFF">


     <script type="text/javascript" language="javascript">
          showImage();
        </script>
    </BODY>
    </HTML> 

    Thanks in advance Sorry i did not post this before

    Kim
    Last edited by kimstanely; 05-05-2006 at 07:53 PM.

  • #4
    Regular Coder
    Join Date
    Sep 2005
    Location
    Chicago, IL
    Posts
    160
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You won't be able to do it with a timer, because a timer only runs while a user is on the page and then resets once they leave. The only way I could think of doing it would be to use the date, but you would have to find a way to relate the date to a picture.
    I'm only telling you how I would do it, not how its supposed to be done. ;)

  • #5
    Senior Coder
    Join Date
    Jul 2005
    Location
    New York, NY
    Posts
    1,084
    Thanks
    4
    Thanked 19 Times in 19 Posts
    ok, so here's a decent enough idea.

    Get all your images into an array.

    Then, get the day of the year.

    Then use modulo on the length of the array and day of year to determine your array index.

    Code:
    var pic;
    
    if (document.images)
    {
        pic = new Array()
    
        pic[0] = new Image(108, 108);
        pic[0].src = "flag_col.jpg";
    
        pic[1] = new Image(108, 108);
        pic[1].src = "books_glasses.jpg";
    
        pic[2] = new Image(108, 108);
        pic[2].src = "lawyers_steps.jpg";
    
        pic[3] = new Image(108, 108);
        pic[3].src = "pen_book.jpg";
    
        pic[4] = new Image(108, 108);
        pic[4].src = "scales1.jpg";
        
        pic[5] = new Image(108,108);
        pic[5].src = 'ccs.gif'
        
        pic[6] = new Image(108,108);
        pic[6].src = 'sj_e.gif'
    }
    
    function getImageByDayOfYear(p_day)
    {
      if (pic.length && pic.length > 0)
      {
        return pic[(p_day - 1)%pic.length];
      }
      else
      {
         return null;
       }
    }
    
    Date.prototype.getDayOfYear = function() {
      var Y = this.getFullYear(), M = this.getMonth(), D = this.getDate();
      return (Date.UTC(Y, M, D) - Date.UTC(Y, 0, 0)) / 86400000;
    };
    
    var doy = new Date();
    var imageToDisplay = getImageByDayOfYear(doy.getDayOfYear());
    DOY code from: http://www.merlyn.demon.co.uk/js-date8.htm#DoY

  • #6
    New Coder
    Join Date
    Apr 2005
    Posts
    27
    Thanks
    0
    Thanked 0 Times in 0 Posts
    hi Beagle,

    When i placed this code in the head it doesn't do anything. is there something i need to do?

    Thanks for the help,
    Kim

  • #7
    New Coder
    Join Date
    Apr 2005
    Posts
    27
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi Beagle,

    Can i do this by using asp, if it can , could you please show me a little example.

    Thanks
    kim

  • #8
    Senior Coder
    Join Date
    Jul 2005
    Location
    New York, NY
    Posts
    1,084
    Thanks
    4
    Thanked 19 Times in 19 Posts
    What do you mean it doesn't work?

    If you want to paste the errors you get, we can help you from there.

    As for ASP, I'm more experienced in PHP, better ask once you get the javascript down in the ASP forum.

  • #9
    Regular Coder
    Join Date
    Sep 2005
    Location
    Chicago, IL
    Posts
    160
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by kimstanely
    Hi,


    Is there a way that i can update something, after 2 weeks, i think we can do this by using timer but i am having a little problem doing that. Can some ont please help!!!!

    Thanks
    Kim
    I seen that you edited your first post from daily to bi-weekly (you can see the last edited tag under your post). I would suggest that if you want to get help that is relevant to what you wanna do that you decide for sure how often the picture needs to change. Because you have another post on here for the same thing, but changing the pictures after a certain amount of seconds.
    I'm only telling you how I would do it, not how its supposed to be done. ;)

  • #10
    New Coder
    Join Date
    Apr 2005
    Posts
    27
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi beagle,

    Could you please let me know where should i place the Script you gave.
    Because when i copy the code you gave and pasted it in my file there was no error but the page was blank

    Thanks,
    Kim

  • #11
    Senior Coder
    Join Date
    Jul 2005
    Location
    New York, NY
    Posts
    1,084
    Thanks
    4
    Thanked 19 Times in 19 Posts
    Kim,
    You need to put the script I gave you in script tags in the head of the document.

    Then you need to call the getImageByDayOfYear to get the image you want.

    something like:

    Code:
    <body onload="document.getElementById('img1').src = getImageByDayOfYear((new Date()).getDayOfYear()).src;">

  • #12
    New Coder
    Join Date
    Apr 2005
    Posts
    27
    Thanks
    0
    Thanked 0 Times in 0 Posts
    hi,

    Thanks beagle, it works but the first who images flash before they change. Also can i set it to work that the image change after 2 weeks.


    Thanks for all the help.

    Kim

    PHP Code:
    <html>
    <
    head>
    <
    script type="text/javascript">
    var 
    pic;

    if (
    document.images)
    {
        
    pic = new Array()

        
    pic[0] = new Image(108108);
        
    pic[0].src "flag_col.jpg";

        
    pic[1] = new Image(108108);
        
    pic[1].src "books_glasses.jpg";

        
    pic[2] = new Image(108108);
        
    pic[2].src "lawyers_steps.jpg";

        
    pic[3] = new Image(108108);
        
    pic[3].src "pen_book.jpg";

        
    pic[4] = new Image(108108);
        
    pic[4].src "scales1.jpg";
        
        
    pic[5] = new Image(108,108);
        
    pic[5].src 'ccs.gif'
        
        
    pic[6] = new Image(108,108);
        
    pic[6].src 'sj_e.gif'
    }

    function 
    getImageByDayOfYear(p_day)
    {
      if (
    pic.length && pic.length 0)
      {
        return 
    pic[(p_day 1)%pic.length];
      }
      else
      {
         return 
    null;
       }
    }

    Date.prototype.getDayOfYear = function() {
      var 
    this.getFullYear(), this.getMonth(), this.getDate();
      return (
    Date.UTC(YMD) - Date.UTC(Y00)) / 86400000;
    };

    var 
    doy = new Date();
    var 
    imageToDisplay getImageByDayOfYear(doy.getDayOfYear());

    </script>
    </head>

    <body onload="document.getElementById('img1').src = getImageByDayOfYear((new Date()).getDayOfYear()).src;">

    <img src="pen_book.jpg" id="img1">
    </body>

    </html> 

  • #13
    Senior Coder
    Join Date
    Jul 2005
    Location
    New York, NY
    Posts
    1,084
    Thanks
    4
    Thanked 19 Times in 19 Posts
    you can modify the code to do whatever you want...

    Right now, you're going off of the day of the year. You could divide that number by 14 rounded down to get every two weeks.

    as for the flickering of the initial img, try not giving a source at all when you create it in the html. just <img src="" />

    That might help.


  •  

    Posting Permissions

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