JavaScript‎ > ‎

Prompt Box


<html>
<head>
<script type="text/javascript">
function show_prompt()
{
var name=prompt("Please enter your name","John Doe");
if (name!=null && name!="")
  {
  document.write("Hello " + name + "! How are you today?");
  }
}
</script>
</head>
<body>

<input type="button" onclick="show_prompt()" value="Show prompt box" />

</body>
</html>

If the user clicks "OK" the box returns the input value. If the user clicks "Cancel" the box returns null.

Comments