How to use Window Object Prompt in JavaScript

In this article I am going to explain about window object prompt() method in JavaScript.
  • 1108

JavaScript Window Object Prompt() Method

JavaScript Prompt() Method use for open a dialog box that take input from user. Prompt dialog box return a string value that entered by user.

Syntax

 

Window.Prompt(Message,Default display text)

Example

<html>

<head>

    <p id="tst">

    </p>

    <script type="text/javascript">

        function myfun() {

            var mm;

 

            var name = prompt("Enter Your Name", "prabhakar");

 

            if (name != null) {

                mm = "Hello " + name;

                document.getElementById("tst").innerHTML = mm;

            }

        }

    </script>

</head>

<body>

    <button onclick="myfun()">

        click me</button>

</body>

</html>

 

Output


prompt1.gif


Enter value and click ok


prompt2.gif

 

You may also want to read these related articles: here
 
Ask Your Question 
 
Got a programming related question? You may want to post your question here
 

Categories

More Articles

© 2013 dotNetheaven. All rights reserved.