Alert Box
An alert box is used if you want to make sure that user has provided the information .
user have to click "OK" to proceed whenever pop-up arises.
Syntax
window.alert("sometext");
Example:
<!DOCTYPE html>
<html>
<body>
<p>Click the button for alert box</p>
<button onclick="me()">Try it</button>
<script>
function me() {
alert("I am an alert box!");
}
</script>
</body>
</html>
Confirm Box
A confirm box is used if you user needs to verify something.
user needs to click either "OK" or "Cancel" to proceed, whenever pop-up box arises
If the user clicks "OK", the box returns true. If the user clicks "Cancel", the box returns false.
Syntax
window.confirm("sometext");
Example:
<!DOCTYPE html>
<html>
<body>
<p>Click the button for a confirm box.</p>
<button onclick="confm()">Try it</button>
<p id="c"></p>
<script>
function confm() {
var x;
if (confirm("Press a button!") == true) {
x = "user pressed OK!";
} else {
x = "user pressed Cancel!";
}
document.getElementById("c").innerHTML = x;
}
</script>
</body>
</html>
0 Comment(s)