...

View Full Version : Resolved Image of text in place of text.



effpeetee
07-27-2009, 07:31 PM
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.:D

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.:D

Frank,

Old Pedant
07-27-2009, 08:59 PM
How about this?


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.

effpeetee
07-27-2009, 09:18 PM
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,

Old Pedant
07-27-2009, 10:17 PM
Sorry...goof on this line:


document.write('<img src="' + when + '.png" alt="Good ' + when + '">\n");

Last " there should be ' thus:


document.write('<img src="' + when + '.png" alt="Good ' + when + '">\n');


Sloppy of me.

effpeetee
07-27-2009, 10:36 PM
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.

effpeetee
07-28-2009, 01:56 PM
Working well now,
see it here. (http://exitfegs.co.uk/)

Many thanks Old Pedant.

from another old pedant.

Frank



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum