JavaScript | Dialogue Boxes - GeeksforGeeks

01 Apr, 2022
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. 
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 : 
JavaScript
<!DOCTYPE html><html>   <head>               <script 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 :
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 :
JavaScript
<!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 :
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 :
JavaScript
<!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 :
Example :
JavaScript
<!DOCTYPE html><html><body>    <p>Line-Breaks</p>    <button onclick="alert('GEEKSFOR\nGEEKS')">CLICK ME</button>  </body></html>
Output :
 
sweetyty
manasborse123
javascript-form
HTML
JavaScript
Web Technologies
HTML
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
How to insert spaces/tabs in text using HTML/CSS?
Top 10 Projects For Beginners To Practice HTML and CSS Skills
How to update Node.js and NPM to next version ?
How to set the default value for an HTML <select> element ?
Hide or show elements in HTML using display property
Remove elements from a JavaScript Array
Convert a string to an integer in JavaScript
Difference between var, let and const keywords in JavaScript
How to calculate the number of days between two dates in javascript?
Differences between Functional Components and Class Components in React