Documentation and Books

Recent site activity

Web Development‎ > ‎JavaScript‎ > ‎

How to prompt the user for a question and answer?

The following example will prompt the user with a question:

  <html>
<head>
<script language="JavaScript">
function displayPrompt() {
var value= prompt('Please type in your name:', 'noname');
alert(value);
}
</script>
</head>
<body>
<input type="button" onclick="displayPrompt();" value="Click Me!"/>
</body>
</html>

The first argument of the prompt function is the question you want to ask, the second argument is the default awnser.