JavaScript | Dialogue Boxes
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 :
Recommended Posts:
- AngularJS | Select Boxes
- Introduction to JavaScript Course | Learn how to Build a task tracker using JavaScript
- JavaScript Course | Understanding Code Structure in JavaScript
- JavaScript Course | Conditional Operator in JavaScript
- JavaScript Course | Logical Operators in JavaScript
- JavaScript Course | Printing Hello World in JavaScript
- JavaScript Course | Data Types in JavaScript
- JavaScript Course | Loops in JavaScript
- JavaScript Course | Operators in JavaScript
- JavaScript Course | Objects in JavaScript
- JavaScript Course | JavaScript Prompt Example
- JavaScript Course | Variables in JavaScript
- JavaScript Course | Functions in JavaScript
- JavaScript vs Python : Can Python Overtop JavaScript by 2020?
- How to include a JavaScript file in another JavaScript file ?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



