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?
You’re probably looking for
confirm()
, which displays a prompt and returnstrue
orfalse
based on what the user decided:How to do this using 'inline' JavaScript:
You can intercept the
onSubmit
event ising JS. Then call a confirmation alert and then grab the result.Or simply: