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 10 of 10
  1. #1
    New to the CF scene
    Join Date
    Sep 2008
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    js for a date month year form

    Hello to everyone
    I am working in a form which has 3 inputs (Day Month Year) and a submit button.I dont know how to make the submit button load a single page, so that every time having different images (depending from the exact date)! I dont know if thats possible because i dont want to load my server with 200 (as many are my dates) different pages! I cant imagine a js that would do that

    Thanks in advance

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,243
    Thanks
    203
    Thanked 2,555 Times in 2,533 Posts
    In principle you want something like this, where your images are named day1.jpg, day2.jpg, day3.jpg ... and so on up to day366.jpg.

    Code:
    <script type = "text/javascript">
    Date.prototype.getDOY = function() {
    var onejan = new Date(this.getFullYear(),0,1);
    return Math.ceil((this - onejan) / 86400000);
    } 
    var today = new Date();
    var DOY = today.getDOY();   // returns xth day of year
    
    alert (DOY);  //delete after testing
    
    document.write("<p align='center'><img src='day' + DOY + '.jpg' width=271 height=168 border= 0></p>");
    
    
    </script>
    BTW, the time to say "thanks" is afterwards, not beforehand which gives the impression that you take other people's unpaid assistance for granted. Or as British politician Neil Kinnock put it, "Don't belch before you have had the meal." Prefer to use "please" beforehand and if you find a response helpful then you can use the "Thank User For This Post" button.

  • #3
    New to the CF scene
    Join Date
    Sep 2008
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Ok Philip.....
    Your comments was very interesting!
    Unfortunately the code doesn t work! I ve tested with a jpg named day250 but it did nt load it!
    Any idea what goes wrong?

  • #4
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,243
    Thanks
    203
    Thanked 2,555 Times in 2,533 Posts
    Quote Originally Posted by delgado View Post
    Ok Philip.....
    Your comments was very interesting!
    Unfortunately the code doesn t work! I ve tested with a jpg named day250 but it did nt load it!
    Any idea what goes wrong?
    Well, it works fine for me. Is your image in the right directory?

  • #5
    New to the CF scene
    Join Date
    Sep 2008
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I am sorry but i cant fix it.
    Could i do this?I have a link in the first page. Could i transform your code so that it would read the image name from the directory and load it in a second page. I want to do this for different link its time (which is the different date).lLoad the same page but with different image every time!
    If so what would like the link in the first page?
    <a href="index.html"+'nameoftheimage'> ??????

  • #6
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,243
    Thanks
    203
    Thanked 2,555 Times in 2,533 Posts
    Quote Originally Posted by delgado View Post
    I am sorry but i cant fix it.
    Could i do this?I have a link in the first page. Could i transform your code so that it would read the image name from the directory and load it in a second page. I want to do this for different link its time (which is the different date).lLoad the same page but with different image every time!
    If so what would like the link in the first page?
    <a href="index.html"+'nameoftheimage'> ??????
    I am afraid that I do not really understand what you are trying to do.

    My script will load a (different) image appropriate to the day of the year.
    If you want something else you need to spell out clearly exactly what it is (and perhaps re-read my "interesting" comments).

  • #7
    New to the CF scene
    Join Date
    Sep 2008
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hello
    First of all accept my apologies if i confused you or made you nervous....it s my first time posting in a forum and i understand that you are trying to help without even knowing me....

    I have 100 links in the first page!I want a script or something, so that when you press the first link, to read the name of the images from the directory and load the appropriate in a "second"page. I want to do this for every link, so that not have to load my server with 100 different pages, but load it with 100 images and 1 "second" page which would work as a template.Can you get it or i was nt clear enough again?

    Thank you and i really appreciate your time spending for answering me.

  • #8
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,243
    Thanks
    203
    Thanked 2,555 Times in 2,533 Posts
    Is this what you are after?

    Code:
    <a href="javascript:displayImage('http://YourSite.com/Image1.gif','500','400')">Image 1</a>
    <a href="javascript:displayImage('http://Yoursite.com/Image2.gif','500','400')">Image 2</a>
    <a href="javascript:displayImage('http://YourSite.com/Image3.gif','500','400')">Image 3</a>
    
    <script type = "text/javascript">
    var popWin = "";
    function displayImage(url, strWidth, strHeight) {
    if (popWin != "") {popWin.close()}
    leftStr = (screen.width-strWidth)/2;
    topStr = (screen.height-strHeight)/2-50;
    windowProperties = "toolbar=no,menubar=no,scrollbars=no,statusbar=no,height="+strHeight+",width="+strWidth+",left="+leftStr+",top="+topStr+"";
    displayImage = window.open(url,'newWin',windowProperties);
    }
    </script>

  • #9
    New to the CF scene
    Join Date
    Sep 2008
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Philip

    That approach what i have in my mind....As you mentioned i am propably not good in giving you right directions in what exactly want but i thought that it would be easy for me to change your initial code to what exactly i want...!
    Could you please guide me so that i would be able to load three images every time aligned verticaly, in a page that i could write whatever i want (or for eg put background color)?

    Why i have to refresh my page in order to activate again your js to work????????

    Please give me your opinion....

  • #10
    New to the CF scene
    Join Date
    Sep 2008
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Please response


  •  

    Posting Permissions

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