I have this jquery code that generates a yes/no dialog box when the user click a button.
$('#btnFinalize').click(function()
{
confirm("Are you sure?");
});
But how can I detect if the user click yes/no?
I have this jquery code that generates a yes/no dialog box when the user click a button.
$('#btnFinalize').click(function()
{
confirm("Are you sure?");
});
But how can I detect if the user click yes/no?
confirm()
returns true
if the user clicked "yes" ; and false
if he clicked "no".
So, basically, you could use something like this :
if (confirm("Are you sure?")) {
// clicked yes
}
else {
// clicked no
}
Check the return value of confirm()
; it will be true
or false
:
if(confirm('Are you sure?! DAMN sure?')) {
// yes
}
else {
// no
}
Try this
$('#btnFinalize').click(function()
{
var reply = confirm("Are you sure?");
if (reply)
{
// your OK
}
else
{
// Your Cancel
}
});
confirm()
will return true or false, depending on the answer. So you can do something like:
$('#btnFinalize').click(function()
{
var finalizeAnswer = confirm("Are you sure?");
if(finalizeAnswer) {
// do something if said yes
} else {
// do something if said no
}
});