Google News
logo
Javascript Dialog Boxes
JavaScript has three kind of dialog boxs: 

1. Alert box 
2. Confirm box 
3. Prompt box.

These dialog boxes can be used to raise and alert, or to get confirmation on any input from the users. 
Alert box :
An alert dialog box is mostly used to give a warning message to the users.
<html>
<head>
<title>Javascript Alert Box</title>
 
<script type="text/javascript">
function Alert() {
  alert ("This is a Sample alert message!");
}
</script>
      
</head>
<body>
      
      <form>
         <input type="button" value="Click Here" onclick="Alert();" />
      </form>
</body>
</html>
Output :
Confirm box :
A confirmation dialog box is mostly used to take user's consent on any option. It displays a dialog box with two buttons: Ok Button and Cancel Button.
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.
<html>
<head>
<title>Javascript Confirm Box</title>
 
<script type="text/javascript">
function getConfirmation(){
  var conf_box = confirm("Are you go to www.freetimelearning.com ?");
}
</script>
 
</head>

<body>
 
<form>
 <input type="button" value="Click Here" onclick="getConfirmation();" />
</form>
 
</body>
</html>
Output :
Prompt box :
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.
<html>
<head>
<title>Javascript Prompt Box</title>
 
<script type="text/javascript">
function getBook(){
  var book = prompt("Enter Book Name : ", "");
  document.write("Your book name is : " + book);
}
</script>
 
</head>
<body>
<form>
 <input type="button" value="Click Here" onclick="getBook();" />
</form>
 
</body>
</html>
Output :