Loading, please wait...

Prompt Dialog Box

Prompt Dialog Box

 

The prompt dialog box is mainly used to get input from the user. Means, the Prompt box appeared with a textbox. Mainly, this dialog box is used to get the information or the data from the user which is required for the further actions on the webpage.

 

The prompt box also appeared with two buttons: “OK” and “Cancel” button. Here, we use an inbuilt function prompt().

 

If the user clicks “OK” then the box returns the input value and if the user clicks “Cancel” then box returns null.

 

 

Code:

<html>
<body>
<h1>JavaScript Prompt Box</h1>
<button onclick="Prompt()">Click Me!</button>

<script>
function Prompt()
{
    var value = prompt("Welcome:", "TutorialsLink!"); 
    document.write(value);
}
</script>
</body>
</html>

 

As per by clicking the Click Me! Button then the browser shows a dialog box with a message and a textarea.

 

Here, in this prompt dialog box, it contains two fields. The first field contains the data which is to be displayed in a popup box and the second field contains data in an input text filed.

 

 

Output: