www.webdeveloper.com
Page 2 of 2 FirstFirst 12
Results 16 to 29 of 29

Thread: new image every week

  1. #16
    Join Date
    Mar 2006
    Posts
    10
    Ah, it starts with 0!
    Any way to make it start with 1?

    (I have others who will be populating the images, and I'd like to K.I.S.S.)



    And how can I also make this change sequential text files on Monday for virtual SSI includes?

    I tried this, but it didn't work. I'm sure I've got something totally wrong:

    <script>
    function mondayText(){
    var n, now= new Date(), d= new Date(now.getFullYear(), 0, 0);
    while(d.getDay()!== 1) d.setDate(d.getDate()+1);
    n= Math.floor((now-d)/6.048e8);
    document.getElementById('mondaytext').src= '/text'+n+'.txt';
    }
    window.onload=mondayText;
    </script>
    </head>

    <body>
    <!--#include virtual id='mondaytext' src="" -->
    </body>
    </html>
    Last edited by LambdaEnt; 03-29-2012 at 02:00 AM.

  2. #17
    Join Date
    Mar 2012
    Posts
    202
    Just add 1 to the n variable like this:

    Code:
    n= Math.floor((now-d)/6.048e8)+1;

  3. #18
    Join Date
    Mar 2012
    Posts
    202
    You can't use an algorithm to dynamically decide the location of a server-side include as far as I know, but especially if the code is running on the client side (like the JavaScript you're trying to use). I think you need to look at a basic AJAX tutorial and see if you can combine your code to make it fit. I hope that helps.

  4. #19
    Join Date
    Mar 2012
    Posts
    202
    You may also want to try using an iframe if you find AJAX too complicated.

  5. #20
    Join Date
    Mar 2012
    Posts
    202
    http://www.w3schools.com/ajax/tryit....=tryajax_first
    Code:
    function loadXMLDoc()
    {
    var xmlhttp;
    if (window.XMLHttpRequest)
      {// code for IE7+, Firefox, Chrome, Opera, Safari
      xmlhttp=new XMLHttpRequest();
      }
    else
      {// code for IE6, IE5
      xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    xmlhttp.onreadystatechange=function()
      {
      if (xmlhttp.readyState==4 && xmlhttp.status==200)
        { // Notice the element output here
        document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
        }
      }
    
    // This is where you would likely put your code
    
    // The filename variable is changeable with JavaScript from here
    xmlhttp.open("GET","ajax_info.txt",true);
    xmlhttp.send();

  6. #21
    Join Date
    Mar 2012
    Posts
    202
    Also notice the AJAX call may not actually process unless you upload it to a server to test it

  7. #22
    Join Date
    Mar 2006
    Posts
    10
    How might I use an iframe?

  8. #23
    Join Date
    Mar 2006
    Posts
    10
    How might I use an iframe?

    Woud it no be possible to get that same +n+ variable in the SSI code?

    <!--#include virtual="/text1.txt" -->
    Last edited by LambdaEnt; 03-31-2012 at 04:31 PM.

  9. #24
    Join Date
    Mar 2006
    Posts
    10
    Anyone here???

  10. #25
    Join Date
    Dec 2005
    Location
    FL
    Posts
    7,389

    Arrow

    Quote Originally Posted by LambdaEnt View Post
    How might I use an iframe?

    Woud it no be possible to get that same +n+ variable in the SSI code?

    <!--#include virtual="/text1.txt" -->
    I don't understand the question, so this might not help...
    See: http://www.devarticles.com/c/a/JavaS...in-JavaScript/
    or: http://www.dyn-web.com/tutorials/iframes/
    or: http://www.ehow.com/how_8520168_call...avascript.html

  11. #26
    Join Date
    Mar 2012
    Posts
    202
    Quote Originally Posted by LambdaEnt View Post
    How might I use an iframe?

    Woud it no be possible to get that same +n+ variable in the SSI code?

    <!--#include virtual="/text1.txt" -->
    Code:
    document.write("<iframe src=\""+urlVariable+"\"></iframe>");

  12. #27
    Join Date
    Mar 2006
    Posts
    10
    Sorry, although I'm not at all new to HTML, I am very new to this stuff. I am learning as fast as I can.

    That answer left out a lot of pieces. Could you perhaps hold my hand a little? I often learn best by example. If you could give me more (if not the whole) ball of wax, it would help a great deal, and better educate me.

    Thank you!

  13. #28
    Join Date
    Sep 2006
    Location
    new york
    Posts
    266
    Might this help?

    http://javascript.about.com/library/blweekyear.htm

    The first thing we need to do is to work out how we define when a week starts and finishes and how we determine which week a particular date is in. The getDay() method returns a value of 0 for Sunday and 6 for Saturday so let's start by defining our week as running from Sunday to Saturday. The 1st January can fall on any day of the week and so not all of the days in that week will be in the current year but we'll consider the week that contains the 1st January to be week one of the current year even though not all of the days in that week are necessarily in the current year. So week one consists of those days between 1st January and the first Saturday on or after that date and the seven days following that make up week two and so on. Once we get to the end of December the last few days of the year will be in week 53 (or possibly 54 if it is a leap year starting on a Saturday).
    I wonder about Leap Year 2012 and the fact that days, months, etc. start with zero.

  14. #29
    Join Date
    Mar 2006
    Posts
    10
    The method about (#3) for changing the pics works perfectly fine, and I am using it! Just now need to adapt it to change text.

    The previous person put up some code, but only part of it. I need more of the whole picture, please.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

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



Recent Articles