JavaScript Confirm
The JavaScript confirm function is quite similar to the alert function, as both display a small dialogue box that appears in front of the current web page. However, the confirm box differs by providing the user with a choice: they can either press "OK" to agree with the message or "Cancel" to decline.
Confirm boxes are commonly used to validate significant actions on a website. For instance, they might be employed to confirm an order submission or to inform users that a link they've clicked will direct them to another website.
JavaScript Confirm Example
Below is an example of how you would use a confirm dialogue box to warn users about something, giving them the option to either continue on or stay put.HTML & JavaScript Code:
<html>
<head>
<script type="text/javascript">
function confirmation() {
var answer = confirm("Leave decoder-log.blogspot.in?")
if (answer){
alert("Bye bye!!!")
window.location = "http://www.google.com/";
}
else {
alert("Thanks for visiting!")
}
}
</script>
</head>
<body>
<form>
<input type="button" onclick="confirmation()" value="Leave decoder-log.blogspot.in">
</form>
</body>
</html>
No comments:
Post a Comment