Claim your Biolink Click Here
0 like 0 dislike
2.0k views
How do I display an OK/Cancel dialog box from JavaScript?
in Education & Reference by | 2.0k views

2 Answers

0 like 0 dislike
Best answer
The JavaScript confirm function is very similar to the JavaScript alert function. A small dialogue box pops up and appears in front of the web page currently in focus. The confirm box is different from the alert box. It supplies the user with a choice; they can either press OK to confirm the popup's message or they can press cancel and not agree to the popup's request.
 
Confirmation are most often used to confirm an important actions that are taking place on a website. For example, they may be used to confirm an order submission or notify visitors that a link they clicked will take 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.
 
<!-- JS-->
<script type="text/javascript">
<!--
function confirmation() {
var answer = confirm("Are your Sure you want to SAVE?")
if (answer){
 
}
 
}
//-->
</script>
 
<!-- HTML CODE -->
 
<input type="button" name="submit" id="submit" value="Submit" class="button"  onClick="return confirmation();" />
by
selected by
0 like 0 dislike

A confirmation dialog box is mostly used to take user's consent on any option. It displays a dialog box with two buttons: OK and Cancel.

If the user clicks on OK button the window method confirm() will return true. If the user clicks on the Cancel button confirm() returns false. You can use confirmation dialog box as follows:

<script type="text/javascript">
<!--
function con()
{
var answer = confirm ("Are you Sure?")
if (answer)
{
alert('OK');
return true;
}
else
{
alert('Cancel');
return false;
}
}
// -->
</script>
 
 
<input type="submit" value="Submit" onclick="return con();"  />
 
 
by

Related questions

2 like 0 dislike
1 answer
0 like 0 dislike
1 answer
0 like 0 dislike
2 answers
0 like 0 dislike
1 answer
asked Apr 25, 2014 in Education & Reference by Neha (1.1k points) | 1.0k views
0 like 0 dislike
1 answer
1 like 0 dislike
3 answers
1 like 0 dislike
1 answer
0 like 0 dislike
1 answer
0 like 0 dislike
1 answer

Where your donation goes
Technology: We will utilize your donation for development, server maintenance and bandwidth management, etc for our site.

Employee and Projects: We have only 15 employees. They are involved in a wide sort of project works. Your valuable donation will definitely boost their work efficiency.

How can I earn points?
Awarded a Best Answer 10 points
Answer questions 10 points
Asking Question -20 points

1,310 questions
1,471 answers
569 comments
4,809 users