Newbie Javascript Question

S

Steevo

Does anyone know how I can alter the following script so that I can place it
in the header of my web page. I would then like to be able to insert a
command in the body section to make the "good morning" etc. appear?


<SCRIPT LANGUAGE="JavaScript">
today = new Date();
time = today.getHours();
if(time < 12)
{document.write("Good Morning")}
else
if(time <18)
{document.write("Good Afternoon")}
else
{document.write("Good Evening, ")}
</SCRIPT>



Many thanks
 
R

Randell D.

Steevo said:
Does anyone know how I can alter the following script so that I can place it
in the header of my web page. I would then like to be able to insert a
command in the body section to make the "good morning" etc. appear?


<SCRIPT LANGUAGE="JavaScript">
today = new Date();
time = today.getHours();
if(time < 12)
{document.write("Good Morning")}
else
if(time <18)
{document.write("Good Afternoon")}
else
{document.write("Good Evening, ")}
</SCRIPT>



Many thanks

You can place the following code anywhere... in the HEAD or BODY...

<SCRIPT LANGUAGE="JavaScript">
function greetMessage()
{
today = new Date();
time = today.getHours();
if(time < 12)
{document.write("Good Morning")}
else
if(time <18)
{document.write("Good Afternoon")}
else
{document.write("Good Evening, ")}

}
</SCRIPT>

Then... to use it, just use the following

<SCRIPT LANGUAGE="JavaScript">
greetMessage();
</SCRIPT>


I'm also a newbie at javascript, but I am pretty sure that should do what
you want...

randelld
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,679
Members
48,796
Latest member
Greg L.

Latest Threads

Top