This really needs to be done with a callback. The closest thing to what you need is to use the publish and subscribe model with some custom events.
For this:
When the user clicks the Yes button, fires a custom event called clickedYes. Do the same for no
$('#yesbtn').click(function(){ $(document).trigger('clickedYes'); }); $('#nobtn').click(function(){ $(document).trigger('clickedNo'); });
Now we need to βlistenβ or subscribe to these events and take the appropriate action in context.
Allows you to create a hypothetical situation . The user presses the delete button and you want to confirm this selection.
First configure what you want if they click yes:
$(document).unbind('clickedYes');
what you want if you don't click no:
$(document).unbind('clickedNo'); //Unbind any old actions $(document).bind('clickedNo',function(){ //Hide the popup and don't delete });
So, we set the actions that clickedYes listen to or click No. Now we just need to show the user a pop-up window so that they click yes or no. When they do, they will trigger the events above.
therefore, your myConfirm () function will do the following:
function myConfirm(msg){
Thus, the order will be as follows:
- Bind triggers for custom events to buttons yes and no
- Before the challenge - untie all the old actions and attach new ones.
- Provide the user with a pop-up window that forces them to activate your actions.
This will allow you to call a function like this myConfirm ("Are you sure"); This is not exactly what you need ... but I do not think it is possible to do exactly what you want.
Brad barrow
source share