How to use Prompt Box in JavaScript
In this article I have described about prompt box used in JavaScript
JavaScript Popup Box
JavaScript provides the ability to pickup user input or small amount of text to user by using Popup box or Dialog Box.
Prompt
JavaScript provides a prompt dialog box to customize any webpage output based on user input for user interaction.
Syntax
prompt("<message>","<default value>");
example
prompt( "Enter Your Name : ", "Name");
Lets take an Example
<html xmlns="http://www.w3.org/1999/xhtml">
<html>
<body>
<button onclick="myFunction()">click</button>
<p id="val" /p>
<script type="text/javascript">
function myFunction() {
var a;
var name = prompt("Please enter your name");
if (name != null)
{
a = "Hello " + name + "Welcome To MCN";
document.getElementById("val").innerHTML = a;
}
}
</script>
</body>
</html>
|
OUTPUT
when we enter name and click ok then output shows as
You may also want to read these related articles :
Ask Your Question
Got a programming related question? You may want to post your question here
Programming Answers here