Question

I am using Alertify Jquery plugin for my dialogs. The problem is that a confirm after a confirm does not seem to work:

<img onclick="go()" src="test.jpg">
<script type="text/javascript">
// confirm dialog
function go(){

  alertify.confirm("Reset password?", function (e) {
    if (e) {
        // user clicked "ok"
        secondconfirm();
    } else {
        // user clicked "cancel"
    }
  });
}

function secondconfirm(){

  alertify.confirm("Password is changed<br>Mail it to the user?", function (e) {
    if (e) {
        //Done
        alertify.success("Password reset and mailed to user.");
    } else {
        // user clicked "cancel"
        alertify.success("Password reset.");
    }
  });
}
</script>

I want to use it this way because based on clicking yes or no a second question has to be asked. If I use it like this, the second confirm dialog appears very shortly and then pops out of screen. Even more annoying, the DIV that covers the rest of the screen stays in place so I can't even use the site naymore without refreshing the whole page. I guess it has something to do with the first dialog being faded out, also hiding the second one.

How to solve this?

Was it helpful?

Solution

Try to delay the execution of the secondconfirm method's body by using the setTimeout method:

function secondconfirm() {
    setTimeout(function () {
        alertify.confirm("Password is changed<br>Mail it to the user?", function (e) {
            if (e) {
                //Done
                alertify.success("Password reset and mailed to user.");
            } else {
                // user clicked "cancel"
                alertify.success("Password reset.");
            }
        });
    }, 1000); // I went as low as 300 ms, but higher value is safer :)
    return true;
}

OTHER TIPS

Is it really requires alertify. Can we just try with confirm itself.

if(confirm("Reset password?"))
{
 // user clicked "ok"
 secondconfirm(); 
} 
else
{
// user clicked "cancel"
} 



function secondconfirm(){

  if(confirm("Password is changed<br>Mail it to the user?") {
         //Done
        alert("Password reset and mailed to user.");
    } else {
        // user clicked "cancel"
        alert("Password reset.");
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top