OK/Cancel? in JavaScript Confirm and Prompt Boxes

Posted by bob korbus on 7th November 2009

Confirm BoxThe JavaScript confirm box is not well designed.  All this goes for the prompt box too…
W3Schools.com (a great place for good, FREE computer language tutorials) explains what a confirm box in JavaScript is:

Confirm Box

A confirm box is often used if you want the user to verify or accept something.
When a confirm box pops up, the user will have to click either “OK” or “Cancel” to proceed.
If the user clicks “OK”, the box returns true. If the user clicks “Cancel”, the box returns false.

Here’s what a confirm box looks like:
Confirm Box
When a JavaScript programmer creates a confirm box they designate the text above the buttons but not the text in the buttons themselves.  By default, the choices are OK or Cancel.  When I thought about why those choices bothered me I realized that they’re good choices for many situations.

Take the example shown above.  The text says to “Press a button” and your choices are OK and Cancel.  I’m OK with “OK” but not with “Cancel”.  Why?  Because I don’t know what “cancel” means.  What’s going to happen if I hit that button?  If I hit the “OK” button I presume I will continue with the normal flow of execution of the program.  That obviously won’t happen if I hit “Cancel” but I’m not sure what will happen.  Where will the program take me to?  What will be cancelled?
“Cancel” has a conventional meaning in Microsoft software.  It means “Leave the current window without making any of the changes made in the window”.   But the meaning of “cancel” outside of Windows applications is ambiguous without more information.

Here’s another problem:  “OK” is a response to a question.  (“How are you doing?”,  “OK”)    “Cancel” is not.  Cancel is a command.  “Cancel that!”  When have you ever used “Cancel” in response to a question?  It seems to me the two button choices should be of the same type response since they are alternate responses to the same request.  If someone asks you “How is your car running?” you may say “OK” but if it isn’t OK is your alternate response ever “Cancel”?   If someone asks you “What should I do with the order?” your answer could be “Cancel” but would an alternate response to that question be “OK”?

I would prefer if the alternate default choices for a JavaScript confirm box were Yes and No.  These are common, mutually exclusive alternate responses to a multitude of questions.  I wouldn’t have a big beef about this except it’s not easy to override the bad defaults.  When I Google “JavaScript override OK/Cancel” I get blogs telling people to do all kinds of coding to change the responses.  If they would have used OK and Cancel as the default set of responses and then made it easy to override the default responses with alternate sets of sets of responses like Yes/No  or Continue/Cancel I wouldn’t like it but at least I could get around it easily.  As it is I’m forced to do a bad design or do a whole bunch of coding to get around it.

What do you think?  Can you give me a way to override OK/Cancel?


One Response to “OK/Cancel? in JavaScript Confirm and Prompt Boxes”

  1. WIllie Bounce says:

    I think for confirmation only, this pop-up window works OK. The “Cancel” button has become the universal way of saying: “Forget it, i changed my mind.” Or: “I’m scared, get me out of here without messing anything up.” We should always be presented a Cancel button and know it will leave things as if nothing happened.

    Other combo’s like YES NO CANCEL do not necessarily qualify as a “confirmation” eg:

    Accelerate Radioactive Core Exposure? YES NO CANCEL

    and should be a UI option in JavaScript and all language UI’s because if you ever get this prompt, you will likely want to click CANCEL since you do not know the result of picking either of the remaining options.