Here’s how you display a confirm box using JavaScript.
JavaScript has a function named ‘confirm()‘ which displays the confirm box.
var confirmResult = confirm(“Clicking OK will return true whereas clicking Cancel will return false”);
When you call a JavaScript function containing the above code, a confirm box with two options namely ‘OK’ and ‘CANCEL’ will be displayed. We make use of a variable ‘confirmResult’ to hold the value returned by the ‘confirm()’ function when the user presses ‘OK’ or ‘Cancel’.
A simple example below will make everything clear:
function testingConfirmBox()
{
var confirmBoxReturnValue = confirm(“Click any of the two buttons below and I’ll display an alert telling you the name of the button you clicked
”);
if(confirmBoxReturnValue == true)
{
alert(“You clicked ‘OK’ “);
}
else
{
alert(“You clicked ‘Cancel’ “);
}
}
From the poll results of this post I found that this post did not really help a few people. If you did not get what you expected from this post then please leave a comment with your query. May be I would be able to help
Note: As far as I know, there is no way of changing the ‘OK’ ‘Cancel’ text to something like ‘Yes’ and ‘No’ unless you hack the browsers source code.