JavaScript Popup Boxes

Three types of popup boxes :- Alert box, Confirm Box and Prompt Box.

Alert Box

An alert box is often used if you want to make sure information comes through to the user.

When an alert box pops up, the user will have to click “OK” to proceed.

Syntax :- window.alert("sometext ");

alerthelloworld

Confirm Box

A confirm box is often used if you want the user to verify or accept something.

When a confirm box pops up, the user will have to click either “OK” or “Cancel” to proceed.

If the user clicks “OK”, the box returns true. If the user clicks “Cancel”, the box returns false.

Syntax :- window.confirm("sometext ");
2..1_4-JavaScript-confirm-alertify

Prompt Box

A prompt box is often used if you want the user to input a value before entering a page.

When a prompt box pops up, the user will have to click either “OK” or “Cancel” to proceed after entering an input value.

If the user clicks “OK” the box returns the input value. If the user clicks “Cancel” the box returns null.

Syntax :- window.prompt("sometext ","defaultText ");;

JavaScript-prompt-for-input

Popup boxes are very important part of Javascript, understanding them can help you in various scenarios.
Now if you have understood them well, try writing a javascript program using all three of them.
2 Likes