Search code examples
javascriptjqueryconfirm

JavaScript: How to select "Cancel" by default in confirm box?


I am displaying a JavaScript confirm box when the user clicks on the "Delete Data" button. I am displaying it as shown in this image:

alt text

In the image, the "OK" button is selected by default. I want to select the "Cancel" button by default, so that if the user accidentally presses the enter key, the records will be safe and will not be deleted.

Is there any way in JavaScript to select the "Cancel" button by default?


Solution

  • If you can use jQuery plugin then here is a nice one

    jQuery Impromptu

    To change the default focused button:

    $.prompt('Example 4',{ buttons: { Ok: true, Cancel: false }, focus: 1 });