Help - Search - Members - Calendar
Full Version: help needed please
HTMLHelp Forums > Programming > Client-side Scripting
fearcr
Hello guys,

I want a script in HTML, that shows a messagebox when it opens with: Good day or good evening, so it has to know what time it is. And I also want to show the day with that too.

I have this so far:
CODE
<script>
hour = new Date ().getHours ()

if (hour > 17) {
    alt = 'morning'
} else if (hour > 12) {
    alt = 'afternoon'
} else {    
    alt = 'evening'
}
alert('Good' + alt);
</script>


So now I need to show the days after that, also in a messagebox like alert, could anyone help me?

Thanks,

Fear
pandy
That's JavaScript not HTML. I move the thread to the Clientside Scripting forum.

BTW I wouldn't say after 17 is morning. happy.gif
pandy
You mean the day of the week? It's getDay() .
http://www.javascriptkit.com/jsref/date.shtml

If you start it off like this, it's easier to pick out other values.

CODE
today = new Date()
hour = today.getHours()


Then you can pick out the day of the week the same way.
CODE
day = toaday.getDay()


I don't think you should have a space before the parenthesis, but it works, so maybe I'm wrong about that.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2010 Invision Power Services, Inc.