JavaScript Program to display prompt for user to enter data
Program
<!DOCTYPE html>
<html>
<body>
<p>Click the button to demonstrate the prompt box.</p>
<button onclick="myFunction()">Display prompt</button>
<p id="demo"></p>
<script>
function myFunction() {
var person = prompt("What is your name?", "Bill Gates");
if (person != null) {
document.getElementById("demo").innerHTML =
"Welcome " + person + " to oodlescoop";
}
}
</script>
</body>
</html>
Output
<p class="output">Click the button to demonstrate the prompt box.</p>
<button onclick="myFunction()">Display prompt</button>
<p id="demo"></p>
<script>
function myFunction() {
var person = prompt(
"What is your name?",
"Bill Gates");
if (person != null) {
document.getElementById("demo").innerHTML = "Welcome " +
person + " to oodlescoop";
}
}
</script>