Welcome to TalkGraphics.com
Page 1 of 2 12 LastLast
Results 1 to 10 of 26

Hybrid View

  1. #1
    Join Date
    Oct 2003
    Location
    Kettering, Northamptonshire, UK
    Posts
    48

    Unhappy Dynamic Date Script

    Hi Folks. I'm returning to Web Designer after a few years away and I'm in the middle of designing a fairly straightforward site.

    Historically, I've always had a bit of javascript code (that I've copied and pasted from my previous web creations and that I found somewhere on the 'net) that simply shows the day/date - and it changes daily to automagically to show the current day/date.

    I came to use it on my new site and decided I needed to align the text to the right. Does anyone know what I need to add to the code to allow me to 'align it right'?

    Thanks in advance!

    <style>
    .mydate {
    font: 10px arial;
    color: white;
    }
    </style>
    <SCRIPT LANGUAGE="Javascript"><!--

    // Get today's current date.
    var now = new Date();

    // Array list of days.
    var days = new Array('Sunday','Monday','Tuesday','Wednesday','Thu rsday','Friday','Saturday');

    // Array list of months.
    var months = new Array('January','February','March','April','May',' June','July','August','September','October','Novem ber','December');

    // Calculate the number of the current day in the week.
    var date = ((now.getDate()<10) ? "0" : "")+ now.getDate();

    // Calculate four digit year.
    function fourdigits(number) {
    return (number < 1000) ? number + 1900 : number;
    }

    // Join it all together
    today = days[now.getDay()] + ", " +
    months[now.getMonth()] + " " +
    date + ", " +
    (fourdigits(now.getYear())) ;

    // Print out the data.
    document.write('<span class="mydate">' + today + '</span>');
    //--></SCRIPT>
    Last edited by SteveP; 30 August 2016 at 06:07 AM. Reason: typo in code
    Thanks

    Steve
    Kettering UK

  2. #2
    Join Date
    Aug 2000
    Location
    Harwich, Essex, England
    Posts
    21,919

    Default Re: Dynamic Date Script

    Works fine for me Steve. You probably forgot to hit Apply after changing the text size
    Attached Files Attached Files
    Egg

    Intel i7 - 4790K Quad Core + 16 GB Ram + NVIDIA Geforce GTX 1660 Graphics Card + MSI Optix Mag321 Curv monitor
    + Samsung 970 EVO Plus 500GB SSD + 232 GB SSD + 250 GB SSD portable drive + ISP = BT + Web Hosting = TSO Host

  3. #3
    Join Date
    Aug 2000
    Location
    Harwich, Essex, England
    Posts
    21,919

    Default Re: Dynamic Date Script

    The quickest way would be to move the placeholder to the right.
    Egg

    Intel i7 - 4790K Quad Core + 16 GB Ram + NVIDIA Geforce GTX 1660 Graphics Card + MSI Optix Mag321 Curv monitor
    + Samsung 970 EVO Plus 500GB SSD + 232 GB SSD + 250 GB SSD portable drive + ISP = BT + Web Hosting = TSO Host

  4. #4
    Join Date
    Oct 2003
    Location
    Kettering, Northamptonshire, UK
    Posts
    48

    Default Re: Dynamic Date Script

    Thanks Egg! You were right. Off to SpecSavers!

    Just one more thing. How do I align the text to the right of the placeholder?
    Thanks

    Steve
    Kettering UK

  5. #5
    Join Date
    Dec 2000
    Location
    Hautes Pyrénées, France
    Posts
    5,083

    Default Re: Dynamic Date Script

    it's a lot easier with php
    but your page must be called mypage.php and not mypage.html
    one simple command in the placeholder
    Code:
    <?php echo date("Y"); ?>
    all my sites are php so that i can take advantage of it
    my home page is called any_old_page.html which nothing links to and then the real home page people see is called index.php

    plus don't forget some people disable javascript or use the noscript plugin
    If someone tried to make me dig my own grave I would say No.
    They're going to kill me anyway and I'd love to die the way I lived:
    Avoiding Manual Labour.

  6. #6
    Join Date
    Oct 2003
    Location
    Kettering, Northamptonshire, UK
    Posts
    48

    Default Re: Dynamic Date Script

    Thanks Frank. I'd prefer to use javascript.
    Thanks

    Steve
    Kettering UK

  7. #7
    Join Date
    Oct 2003
    Location
    Kettering, Northamptonshire, UK
    Posts
    48

    Default Re: Dynamic Date Script

    Hi Egg. Cheers, Yes, I can do that but as the date gets bigger/longer, it's currently defaulting to left aligned so the longer dates push the text off the right hand side of the page. If it were right aligned it would push the longer text to the left, where I've got plenty of room
    Thanks

    Steve
    Kettering UK

  8. #8
    Join Date
    Aug 2000
    Location
    Harwich, Essex, England
    Posts
    21,919

    Default Re: Dynamic Date Script

    Try this
    Attached Files Attached Files
    Egg

    Intel i7 - 4790K Quad Core + 16 GB Ram + NVIDIA Geforce GTX 1660 Graphics Card + MSI Optix Mag321 Curv monitor
    + Samsung 970 EVO Plus 500GB SSD + 232 GB SSD + 250 GB SSD portable drive + ISP = BT + Web Hosting = TSO Host

  9. #9
    Join Date
    Oct 2003
    Location
    Kettering, Northamptonshire, UK
    Posts
    48

    Default Re: Dynamic Date Script

    My thanks to Egg for sorting out my alignment issue with the dynamic date script. To keep things exciting ... another issue has arisen!

    I have put the script on the main site and adjusted the font, size and alignment - as expected, it works perfectly.

    It's a responsive site and because I want to make the font smaller for the date on the mobile variant, I copied the script, created a new placeholder and reduced the font size.

    ..then my troubles began!

    Bizarrely, the MAIN site now takes on the font size of the MOBILE site's font settings even though when I look at the placeholder script on the MAIN page, it shows the *larger* font size. After a bit of poking around, I found that if I delete the dynamic date script on the MOBILE page, the MAIN script then behaves itself - ie it shows the larger font size.

    So, I've concluded that it must be a glitch somewhere and if I have the need for the script on BOTH variants, the MAIN website page is always going to adopt the font size of the MOBILE page's script.

    I don't yet know enough about what goes on 'under the bonnet' of WD's web pages to see what's happening. I can only conclude that the MOBILE script seems to 'take priority' over the main page's script.

    I've pulled enough hair out over this , and would really appreciate some guidance from any WD gurus out there.

    Many thanks!
    Thanks

    Steve
    Kettering UK

  10. #10
    Join Date
    Aug 2000
    Location
    Harwich, Essex, England
    Posts
    21,919

    Default Re: Dynamic Date Script

    I would say it's because you are calling the same class i.e. .mytime in both variants. I changed the class name on the mobile version to .mymobileclass and this appears to have done the trick.

    You only need to alter two occasions of the class name in the mobile code.

    EDIT: Amended xar file.
    Attached Files Attached Files
    Egg

    Intel i7 - 4790K Quad Core + 16 GB Ram + NVIDIA Geforce GTX 1660 Graphics Card + MSI Optix Mag321 Curv monitor
    + Samsung 970 EVO Plus 500GB SSD + 232 GB SSD + 250 GB SSD portable drive + ISP = BT + Web Hosting = TSO Host

 

 

Tags for this Thread

Bookmarks

Posting Permissions

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