Skip to content
Fix Code Error

How to create a dialog with “yes” and “no” options?

March 13, 2021 by Code Error
Posted By: Anonymous

I am going to make a button to take an action and save the data into a database.

Once the user clicks on the button, I want a JavaScript alert to offer “yes” and “cancel” options. If the user selects “yes”, the data will be inserted into the database, otherwise no action will be taken.

How do I display such a dialog?

Solution

You’re probably looking for confirm(), which displays a prompt and returns true or false based on what the user decided:

if (confirm('Are you sure you want to save this thing into the database?')) {
  // Save it!
  console.log('Thing was saved to the database.');
} else {
  // Do nothing!
  console.log('Thing was not saved to the database.');
}
Answered By: Anonymous

Related Articles

  • polymer paper-dialog within paper-dialog
  • Polymer paper-dialog: how can I know when an injected dialog…
  • Redirecting from edit to parent resource doesn't (re)render…
  • How to separate Polymer button and dialog
  • Polymer paper-dialog not showing up on click in chrome
  • Onclick, the button moves down, why can that due to?
  • Ember.js: How to refresh parent route templates in a nested…
  • How do the PHP equality (== double equals) and identity (===…
  • Active tab issue on page load HTML
  • Difference between variable declaration syntaxes in…

Disclaimer: This content is shared under creative common license cc-by-sa 3.0. It is generated from StackExchange Website Network.

Post navigation

Previous Post:

jQuery checkbox checked state changed event

Next Post:

Fixed position but relative to container

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

  • Get code errors & solutions at akashmittal.com
© 2022 Fix Code Error