Skip to content
Related Articles

Related Articles

Improve Article

JavaScript | Dialogue Boxes

  • Difficulty Level : Medium
  • Last Updated : 14 Feb, 2019

JavaScript uses 3 kind of dialog boxes : ALERT, PROMPT and CONFIRM. These dialog boxes can be of very much help for making our website look more attractive.

ALERT BOX :

An alert box is used in the website to show a warning message to the user that they have entered the wrong value other than what is required to filled in that position. Nonetheless, an alert box can still be used for friendlier messages. Alert box gives only one button “OK” to select and proceed.
Example :




<!DOCTYPE html>
<html>
   <head>
         
      <scrip</div>t type="text/javascript">
         <!--
            function Warning() {
               alert ("Warning danger you have not filled everything");
               document.write ("Warning danger you have not filled everything");
            }
      </script>
        
   </head>
   <body>
      <p>Click me </p>
        
      <form>
         <input type="button" value="Click Me" onclick="Warning();" />
      </form>
        
   </body>
</html>

Output :

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 on the OK button, the window method confirm() will return true. If the user clicks on the Cancel button, then confirm() returns false and will show null.
Example :




<!DOCTYPE html>
<html>
   <head>
     
      <script type="text/javascript">
  
            function Confirmation(){
               var Val = confirm("Do you want to continue ?");
               if( Val == true ){
                  document.write (" CONTINUED!");
                  return true;
               }
               else{
                  document.write ("NOT CONTINUED!");
                  return false;
               }
            }
  
      </script>
        
   </head>
   <body>
      <p>Click me: </p>
        
      <form>
         <input type="button" value="Click Me" onclick="Confirmation();" />
      </form>
        
   </body>
</html>

Output :



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 the OK button, the window method prompt() will return the entered value from the text box. If the user clicks the Cancel button, the window method prompt() returns null.
Example :




<!DOCTYPE html>
<html>
   <head>
        
      <script type="text/javascript">
           
            function Value(){
               var Val = prompt("Enter your name : ", "name");
               document.write("You entered : " + Val);
            }
    
      </script>
        
   </head>
     
   <body>
      <p>Click me: </p>
        
      <form>
         <input type="button" value="Click Me" onclick="Value();" />
      </form>
        
   </body>
</html>

Output :

LINE BREAKER :

Example :




<!DOCTYPE html>
<html>
<body>
  
<p>Line-Breaks</p>
  
<button onclick="alert('GEEKSFOR\nGEEKS')">CLICK ME</button>
  
</body>
</html>

Output :

Attention reader! Don’t stop learning now. Get hold of all the important Comcompetitivepetitve Programming concepts with the Web Design for Beginners | HTML  course.




My Personal Notes arrow_drop_up
Recommended Articles
Page :