Hi
I have created a html page and want to ask the user to type in his name (prompt box) when index.html page loads and then greet him. I am using JavaScript cookies, but when the user has entered his name and presses OK the greetings message is displayed on a blank page, and not on the homepage.
My code:
<html>
<head>
<script type = "text/javascript">
function message()
{
name = window.prompt("What is your Name?");
if ((name == null)||(name == ""))
{
name = "Unknown";
}
document.cookie = name;
document.write("<p>Greetings " + name + "</p>");
}
</script>
</head>
<body onload = "message()">
<img src = "logo1.jpg">
</body>
</html>
when i remove the document.write("<p>Greetings " + name + "</p>"); in the head and paste it in the body, it doesn't remember the name that was entered and only the word "Greetings" can be seen.
Code:
<body onload = "message()">
<script type = "text/javascript">
document.write("<p>Greetings " + name + "</p>");
</script>
<img src = "logo1.jpg">
</body>
</html>
Can someone please help me.