Using the Prompt Box in JavaScript

Using the prompt box:

The prompt box is used to input a value from the user. It contains a textbox, OK and Cancel buttons. The user has to click either OK or Cancel button to continue the execution of the code after entering the input value. If OK button is clicked, the input value is returned. Otherwise, box returns null value.

Demo:

  1. Create a document called promptBox.html

    notepad

  2. Write the following code:

    code

  3. Execute the script by Opening the file in the Web Browser. If you are using Internet Explore click on “Allow Blocked Content” to allow the script to execute and you are using Mozilla Firefox then click on allow “ActiveX Controls”.

    Execute

    When user enters the name and hits the OK button:

    OK button

    When the user clicks on Cancel button.

    Cancel button
Next Recommended Reading JavaScript Message Box