- The prompt() method displays a dialog box that prompts the visitor for input.
- A prompt box is often when we want the user to input a value before entering a page.When a prompt box pops up, the user will have to click either "OK" or "Cancel" to proceed after entering an input value.If the user clicks "OK" the box returns the input value. If the user clicks "Cancel" the box returns null.
Example::
HTML Code:
<html>
<head>
<script type = "text/javascript">
function getValue() {
var retVal = prompt("Enter your name : ", "your name here");
document.write("Hi : " + retVal);
}
</script>
</head>
<body>
<p>Click to see the result: </p>
<form>
<input type = "button" value = "Click Me" onclick = "getValue();" />
</form>
</body>
</html>
Bookmarks