JavaScript Dialog boxes make a webpage interactive and attractive to user. They are used to give important notification to the user and also can take inputs from them. Different types of boxes provides different features and are used for various purposes. Three different types of dialog boxes are alert box, confirm box, and prompt boxes.
Three different types of dialog boxes:
An alert dialog box displays a short message or notification to the user. It includes only an OK
button. It just give some information, necessary to the user and it can be invoked at various events possible in javascript.
Alert dialog boxes can be created with alert()
method.
A confirm dialog box is used to ask for user confirmation over any matter. It has two buttons OK
and CANCEL
. If the user agrees with whatever written in the box, then he he can click on OK, and then specified action will take place. If the user disagrees, then he can click on CANCEL.
It returns a Boolean value depending on whether the user clicks OK
(true) or CANCEL
(false) button and then a specified action takes place.
The prompt dialog box is used to get some input from the user. There are also two buttons OK
and CANCEL
like confirm box. It returns the text entered in the input field when the user clicks the OK
, and null if user clicks the CANCEL
.
A Prompt box can be created by using prompt()
function.
Follow Us: