This is probably a very simple question, but I can't find the answer, so hopefully someone can help?
How do you cancel a click action if the user clicks 'cancel' in a confirm box?
I have this so far but can't find what I need to fill in the blank.
jQuery('#doaction').click(function(e){
if(jQuery('#bulk-action-selection').val() === 'delete'){
var action = confirm('Are you sure you wish to delete the selected User Groups? This action cannot be undone.');
}
if(action === false){
{ Cancel the click and don't delete the items }
}
});
This is probably a very simple question, but I can't find the answer, so hopefully someone can help?
How do you cancel a click action if the user clicks 'cancel' in a confirm box?
I have this so far but can't find what I need to fill in the blank.
jQuery('#doaction').click(function(e){
if(jQuery('#bulk-action-selection').val() === 'delete'){
var action = confirm('Are you sure you wish to delete the selected User Groups? This action cannot be undone.');
}
if(action === false){
{ Cancel the click and don't delete the items }
}
});
Share
Improve this question
edited Feb 29, 2012 at 11:11
Lightness Races in Orbit
385k77 gold badges666 silver badges1.1k bronze badges
asked Dec 22, 2011 at 9:46
David GardDavid Gard
12.1k42 gold badges128 silver badges261 bronze badges
1
- 1 If user press cancel just don't do anything? – matino Commented Dec 22, 2011 at 9:49
3 Answers
Reset to default 4 if( action === false )
return false;
This should work.
Try this:
jQuery('#doaction').click(function(e){
if(jQuery('#bulk-action-selection').val() === 'delete'){
var action = confirm('Are you sure you wish to delete the selected User Groups? This action cannot be undone.');
if(action === false) {
return false; // this would do
}
}
});
Wont this work:
jQuery('#doaction').click(function(e){ if(jQuery('#bulk-action-selection').val() === 'delete'){ var action = confirm('Are you sure you wish to delete the selected User Groups? This action cannot be undone.'); } else { return false; } });