Loading Please Wait...

Logo Lynxsia IT Solutions

JavaScript Popup Boxes

JS Popup Boxes

JavaScript has three kind 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.

Use window.alert() or alert() method to display the alert box.

					 
        
          alert("This is simple alert box!");
        
      
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.

Use window.confirm() or confirm() method to display the confirm box.

					 
        
          let choice = confirm("Are you sure you want to delete this item?");
          let txt;
          if (choice) {
            txt = "You pressed OK! Item deleted";
          } else {
            txt = "You pressed Cancel! Item not deleted";
          }
        
      
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.

Use window.prompt() or prompt() method to display the prompt box.

					 
        
          let name = prompt("Please enter your name", "Harry Potter");
          let text;
          if (person == null || person == "") {
            text = "User cancelled the prompt.";
          } else {
            text = "Hello " + person + "! How are you today?";
          }
        
      
Line Breaks

To display line breaks inside a popup box, use a back-slash followed by the character n.

					 
        
          alert("Hello\nHow are you?");
        
      

How you feel about this blog:

Share this blog on:

Report Us

If you find any error in the turtorials, or want to share your suggestion/feedback, feel free to send us email at: info@lynxsia.com

Contact Us
Ads
Logo
Lynxsia IT Solutions

We are concern with various development process like website design & development, E-commerce development, Software development, Application development, SMS & Bulk SMS Provider, PWA Development, and many more..

Kotwali Road, Chhiptehri, Banda, 210001, UP, India

Copyright © 2022, Lynxsia IT Solutions, All rights reserved