0% found this document useful (0 votes)
2 views1 page

Practical 4

The document provides a JavaScript function that prompts the user with a confirmation box when a button is clicked. If the user confirms the action, an alert is displayed saying 'You confirmed.' The code includes HTML structure for the button and the script for the confirmation functionality.

Uploaded by

katporiyahardik
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views1 page

Practical 4

The document provides a JavaScript function that prompts the user with a confirmation box when a button is clicked. If the user confirms the action, an alert is displayed saying 'You confirmed.' The code includes HTML structure for the button and the script for the confirmation functionality.

Uploaded by

katporiyahardik
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Q.

-Write a JavaScript function that:


1. Displays a confirmation box asking the user "Are you sure?" when a button
is clicked.
2. If the user confirms, display an alert saying "You confirmed."

code-
<!DOCTYPE html>
<html>
<head>
<title>Confirmation Example</title>
<script>
function confirmAction() {
let result = confirm("Are you sure?");
if (result) {
alert("You confirmed.");
}
}
</script>
</head>
<body>

<button onclick="confirmAction()">Click Me</button>

</body>
</html>

You might also like