How do I add an onclick event to the OK button of the Javascript confirm box?

1.8k views Asked by At

I am working with a .Net 1.1 web application. There is a Save button that, when clicked, will pop up the Javascript confirm box. Once the user clicks OK a long running process is kicked off. We would like to show a busy indicator when the user clicks the OK button of the confirm dialog. Can this be done?

3

There are 3 answers

0
Karl Mendes On BEST ANSWER
if(confirm("Are you sure you would like to save?")){
    alert("Loading") //Replace with what you want to do  
}
0
Diodeus - James MacFarlane On

The button on an alert() dialog is not scriptable. You need to find where in the code the alert() is called and patch in to the code just after this.

0
Akkuma On

What you want to do is pretty simple. A confirm('Text') returns true or false after the user makes their selection. All you need to do is on true show a busy indication.

Here is what you're looking for http://jsfiddle.net/Akkuma/C6ZZf/

$('#save').on('click', function () {
    var shouldSave = confirm('Make your choice');

    if(shouldSave) {
        alert('Do saving');
    }
    else {   
        alert('Not saving'); 
    }
});