Click to See Complete Forum and Search --> : Re: Greeting


Maverick6215
12-16-2003, 12:35 PM
Hi

I've done a search here using Time, Date but haven't come up with anything as yet.

What I would like to do is add a greeting on my site based on the time of day e.g. Good morning, etc.

If this has been covered could someone please direct me to the relevent thread.

Cheers.

fredmv
12-16-2003, 01:15 PM
http://javascript.internet.com/calendars/m-t-dh.html

Maverick6215
12-16-2003, 06:10 PM
Thanks.

Being quite a novice I was hoping for a little extrra help.

I entered the code and it worked first time. I need to amend some of the wording and that looks pretty easy and straight-forward. What I am having difficulty doing is taking out the actual calendar leaving just the greeting and time.

I tried deleting everything from;
function calendar()
to the first } before
document.write("</TABLE>");
but then I get errors.

Any help gratefully appreciated.

Cheers

Paul Jr
12-16-2003, 07:06 PM
I'm no JS Guru, or not even close, but I typed this up. You may have to tweak it to your liking. It's 24 hour time format, so 13 = 1PM, 18 = 6PM, 24 = 12AM ect. ect.


<script type="text/javascript">
var date = new Date ();
var hrs = date.getHours();
if (hrs<=11 && hrs>=6) {
document.write("Good morning.");
}
else if (hrs>=12 && hrs<=16) {
document.write("Good afternoon.");
}
else if (hrs>=17 && hrs<=20) {
document.write("Good evening.");
}
else if (hrs>=21 && hrs<=24) {
document.write("Good night.");
}
</script>

zachzach
12-16-2003, 07:42 PM
mavric, or whatever(lol), try readin some books. I might be able to help, im not a total master but I think I'm pretty good...

Maverick6215
12-17-2003, 07:53 AM
Thanks Paul JR.

That worked a treat. I am gradually learning more and reading up quite a bit but sometimes a little nudge goes a long way.

Cheers.

Maverick6215
12-17-2003, 04:25 PM
OK, I have done some further research but have drawn blanks again. If someone could point to info on the web as to how I set about changing the font, alignment, colour, etc. when using the document.write function I would be most grateful.

I have tried entering the command <font> <colour><alaign=> etc. but I just get errors.

Cheers.

Paul Jr
12-17-2003, 06:19 PM
You should just be able to add in your HTML tags like usual, except you have to use single quotes instead of double -- I also wouldn't recomend using depreciated tags (<font>,<center>,<align="">).

<style type="text/css">
.date {
color:#F00;
font-weight:900;
font-size:125%;
}
</style>
<script type="text/javascript">
var date = new Date ();
var hrs = date.getHours();
if (hrs<=11 && hrs>=6) {
document.write("<span class='date'>Good morning.</span>");
}
else if (hrs>=12 && hrs<=16) {
document.write("<span class='date'>Good afternoon.</span>");
}
else if (hrs>=17 && hrs<=20) {
document.write("<span class='date'>Good evening.</span>");
}
else if (hrs>=21 && hrs<=24) {
document.write("<span class='date'>Good night.</span>");
}
</script>