Here's the code snippet I'm currently using:
<html>
<head>
<link type="text/css" rel="stylesheet" href="html.css" />
<script type="text/javascript">
function getName()
{
if(name)
alert("Did you think I forgot about you, " + name + "?");
else
name=prompt("What's your name?","Please enter it here");
}
</script>
</head>
<body onload="var name;">
<p onclick="getName()"; >Click here</p>
</body>
</html>
When I click the <p>
text for the first time, it prompts me. However, if I click cancel without entering my name and then click the <p>
text again, it doesn't prompt me anything.
Instead, it shows the name value as NULL. In C,
char a=NULL;
if(a)
evaluates to false. Does this same behavior occur in JavaScript?