Using the Confirm Box in JavaScrip

Using the Confirm Box

The confirm box is an advance form of alert box. It is used to display message as well as return a value (true or false). The confirm box displays a dialog box with two buttons, OK and Cancel. When the user clicks on OK button it returns true and when user clicks on Cancel button it returns false. The confirm box enables you to interrupt the JavaScript processing to ask the user a question and then continue processing based on which button is clicked.

Demo:

  1. Create a document named confirmBox.html.

    notepad

  2. Write to 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 you select OK:

    select OK

    When you select Cancel:

    select Cancel
Thanks for reading this blog.
Ebook Download
View all
Learn
View all