Learn JavaScript Popup Box Methods

If you work with javascript – you must know the three important useful method of javascript. JavaScript Popup boxes – In this post, you will learn about javaScript popup and it uses. Javascript popups are of three types: Alert Popup, Confirm Box Popup, Prompt Box Popup. When using pop-up box methods you do not need to write “window” prefix.

Learn JavaScript Popup Box


  • Alert Box
  • Confirm Box
  • Prompt Box

Alert Box

When you need information to access the user, an alert box is used. It disrupts the user’s activity. This is the reason why you need to use it carefully. When the alert box appears, you have to press the OK button to start your activity again.

Syntax Of Alert Box

window.alert("Alert Text!");
alert("How are you?");

Confirm Box

When you need to accept something from the user that we use A confirmation pop-up box. When the confirmation pop-up box is open and you will see the two buttons name close and ok. if you want to agree than click ok button and not agree to close.

Syntax Of Confirm Box

window.confirm("Confirmation Information");

Need to know that – If the “OK” button is clicked, the confirmation box returns “true” . if the “cancel” button is pressed return “false”

var cnfirm = confirm("Confirm something!");
if (cnfirm == true) { 
   x = "OK was pressed";  
else {
   x = "Cancel was pressed";  

Prompt Box

When you need to enter some information before the user goes ahead Then we do use the prompt box. If the user wants to close the prompts box then he will have to press OK or Cancel button.

Syntax Of Prompt Box
window.prompt("Information Text","Default Text");
function firstFunction() {
    var txt_alert;
    var person = prompt("Please enter your full name:", "Harry Potter");
    if (person  == null || person  == "") {
        txt_alert = "User cancelled the prompt.";
    } else {
        txt_alert = "Hello " + person + "! How are you today?"
    document.getElementById("demo_test").innerHTML = txt_alert;

Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *