Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Java by (9.5k points)

I want to create a button with “yes” & “cancel” options. If “yes”, it inserts the data into the database and if “cancel” no action will be taken. 

Can anyone tell me how to create a dialogue box with yes and no options in JavaScript?

1 Answer

0 votes
by (19.7k points)

No, you cannot create a dialogue box with yes and no in JavaScript. But the Window.confirm() method will make a dialogue box with OK(true) and Cancel(false) buttons along with an optional message. 

Here’s the syntax from the official website: 

result = window.confirm(message);

Take a look at the code snippet below:

if (confirm('Are you sure you want to save this thing into the database?')) {

  // User selects “OK”

  console.log('Thing was saved to the database.');

} else {

  // User selects “Cancel” 

  console.log('Thing was not saved to the database.');

}

If you want to learn more about Javathen go through this Java tutorial by Intellipaat for more insights.

Browse Categories

...