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 6 of 6
  1. #1
    Senior Coder effpeetee's Avatar
    Join Date
    Feb 2007
    Location
    Clapham Junction - London SW
    Posts
    4,885
    Thanks
    228
    Thanked 204 Times in 203 Posts

    Exclamation Image of text in place of text.

    Code:
    function greet() {
      var todaydate = new Date();
      var timeis = todaydate.getTime();
      todaydate.setTime(timeis);
      var houris = todaydate.getHours();
      if (houris >17) display = "Good Evening";
      else if (houris >11) display = "Good Afternoon";
      else display = "Good Morning";
      var welcome = (display );
      document.write(welcome);
    }

    I want this function to present something.png instead of the text for Good Morning etc.

    if (houris >17) display =gm.png; in this fashion.

    I would appreciate any help.

    Also IE8 reports "clientside is undefined" as an error message, occasionally.
    My javascript knowledge is still rudimentary so I would appreciate some guidance here as well.

    Frank,
    Last edited by effpeetee; 07-28-2009 at 11:16 PM.
    * Sources (updated: 21.11.2012.
    Using Windows 8 Professional. 64bit with HP Photosmart 5510 printer Very useful site here.

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,600
    Thanks
    80
    Thanked 4,633 Times in 4,595 Posts
    How about this?
    Code:
    function greet() 
    {
      var hour = (new Date()).getHours();
      var when = (hour > 17) ? "Evening" : ( (hour > 11) ? "Afternoon" : "Morning" );
      document.write('<img src="' + when + '.png" alt="Good ' + when + '">\n");
    }
    None of the parens in the "when=" line are needed, but they make it much clearer. I put the alt= in there so it will validate. Killed two birds with one stone.

    Not sure what the purpose of your code that did the setTime() to the same value as the getTime() was. Basically, that meant you changed nothing at all.

  • #3
    Senior Coder effpeetee's Avatar
    Join Date
    Feb 2007
    Location
    Clapham Junction - London SW
    Posts
    4,885
    Thanks
    228
    Thanked 204 Times in 203 Posts
    Many thanks, I'll amend my page immediately.

    If you click "Home sweet home" at the bottom, you can see the page in question.

    Off to make the .pngs now.

    Frank

    edit: I have reset all options to morning.png and uploaded the morning.png graphic to my root directory.
    Doesn't seem to put anything on screen. The browser IE8, mentions a few js errors. May not be from this function.

    Any ideas. The greeting should head the page,
    Last edited by effpeetee; 07-27-2009 at 10:53 PM.
    * Sources (updated: 21.11.2012.
    Using Windows 8 Professional. 64bit with HP Photosmart 5510 printer Very useful site here.

  • #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,600
    Thanks
    80
    Thanked 4,633 Times in 4,595 Posts
    Sorry...goof on this line:
    Code:
      document.write('<img src="' + when + '.png" alt="Good ' + when + '">\n");
    Last " there should be ' thus:
    Code:
      document.write('<img src="' + when + '.png" alt="Good ' + when + '">\n');
    Sloppy of me.

  • Users who have thanked Old Pedant for this post:

    effpeetee (07-28-2009)

  • #5
    Senior Coder effpeetee's Avatar
    Join Date
    Feb 2007
    Location
    Clapham Junction - London SW
    Posts
    4,885
    Thanks
    228
    Thanked 204 Times in 203 Posts
    Many thanks. Works fine. I.ll do the other png's in the morning.

    Frank

    edit - Tuesday AM - remaining png's now in place.

    Fingers crossed.
    Last edited by effpeetee; 07-28-2009 at 10:54 AM.
    * Sources (updated: 21.11.2012.
    Using Windows 8 Professional. 64bit with HP Photosmart 5510 printer Very useful site here.

  • #6
    Senior Coder effpeetee's Avatar
    Join Date
    Feb 2007
    Location
    Clapham Junction - London SW
    Posts
    4,885
    Thanks
    228
    Thanked 204 Times in 203 Posts
    Working well now,
    see it here.

    Many thanks Old Pedant.

    from another old pedant.

    Frank
    * Sources (updated: 21.11.2012.
    Using Windows 8 Professional. 64bit with HP Photosmart 5510 printer Very useful site here.


  •  

    Posting Permissions

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