
- Javascript Basics Tutorial
- Javascript - Home
- Javascript - Overview
- Javascript - Syntax
- Javascript - Enabling
- Javascript - Placement
- Javascript - Variables
- Javascript - Operators
- Javascript - If...Else
- Javascript - Switch Case
- Javascript - While Loop
- Javascript - For Loop
- Javascript - For...in
- Javascript - Loop Control
- Javascript - Functions
- Javascript - Events
- Javascript - Cookies
- Javascript - Page Redirect
- Javascript - Dialog Boxes
- Javascript - Void Keyword
- Javascript - Page Printing
- JavaScript Objects
- Javascript - Objects
- Javascript - Number
- Javascript - Boolean
- Javascript - Strings
- Javascript - Arrays
- Javascript - Date
- Javascript - Math
- Javascript - RegExp
- Javascript - HTML DOM
- JavaScript Advanced
- Javascript - Error Handling
- Javascript - Validations
- Javascript - Animation
- Javascript - Multimedia
- Javascript - Debugging
- Javascript - Image Map
- Javascript - Browsers
- JavaScript Useful Resources
- Javascript - Questions And Answers
- Javascript - Quick Guide
- Javascript - Functions
- Javascript - Resources
How to show prompt dialog box using JavaScript?
The prompt dialog box is very useful when you want to pop-up a text box to get user input. Thus, it enables you to interact with the user. The user needs to fill in the field and then click OK.
This dialog box is displayed using a method called prompt() which takes two parameters: (i) a label which you want to display in the text box and (ii) a default string to display in the text box.
This dialog box has two buttons: OK and Cancel. If the user clicks the OK button, the window method prompt() will return the entered value from the text box. If the user clicks the Cancel button, the window method prompt() returns null.
Example
You can try to run the following code to earn how to implement prompt dialog box using JavaScript:
<html> <head> <script> <!-- function getValue(){ var retVal = prompt("Enter your name : ", "your name here"); document.write("You have entered : " + retVal); } //--> </script> </head> <body> <p>Click the following button to see the result: </p> <form> <input type="button" value="Click Me" onclick="getValue();" /> </form> </body> </html>
- Related Articles
- Creating a prompt dialog box using Tkinter?
- How to show image in alert box using JavaScript?
- How can I pop-up a print dialog box using JavaScript?
- How to create Dialog Box in ReactJS?
- How to create a Custom Dialog box on iOS App using Swift?
- How to eliminate close button from jQuery UI dialog box using CSS?
- Raise a "File Download" Dialog Box using Perl
- How to show Alert Dialog in iOS?
- How to show alert dialog in Android?
- How to create a Dialog Box without a title in Android using Kotlin?
- How to add check box list in alert dialog?
- How to create a Confirmation Dialog Box in Java?
- How to create a Custom Dialog box on Android?
- How to work with Alerts Dialog box in ReactNative?
- How to set dialog to show with full screen in Android using Kotlin?

Advertisements