JavaScript confirm Function Example
Oftentimes in computer programs, user confirmation is needed before proceeding with an action. JavaScript has a built-in function handle this: confirm().
if (confirm('accept this action?'))
document.write('action accepted');
else
document.write('action denied');
As seen in this example, the JavaScript confirm function takes a string argument. This is what the confirm box should display. The confirm box displays the message, along with with an OK and Cancel button. If OK is clicked, the confirm function returns true. If Cancel is clicked, the confirm function returns false.
Use the JavaScript confirm function as a popup box awaiting user input prior to proceeding with an action.