JavaScript prompt() Method

You are Here:

JavaScript prompt() Method

The prompt() method displays a dialog with an optional message prompting the user to input some text.

This method returns the user typed value.

Example

HTML Online Editor
<!DOCTYPE html> <html> <body> <p onclick="myFunction()">Click me</p> <p id="point"></p> <script> function myFunction(){ var ans = prompt("How old are you?", 35); var txt = "You replied: " +ans document.getElementById("point").innerHTML = txt; } </script> </body> </html>

Syntax

prompt(question, answer)

Parameter Values

ValueTypeExplanation
questionRequiredA question to display to the user.
answerOptionalSpecifies a default answer.

Return Value

ValueExplanation
StringReturns the user typed value.

Reminder

Hi Developers, we almost covered 97% of JavaScript Tutorials with examples for quick and easy learning.

We are working to cover every Single Concept in JavaScript.

Please do google search for:

Join Our Channel

Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.

This channel is primarily useful for Full Stack Web Developer.

Share this Page

Meet the Author