tags:

views:

38

answers:

2

I have a confirmation dialogue that pops after you hit ("#step0Next") on a form wizard. Currently it pops after you hit the button on the next step. I need it to pop when you hit the button on THAT step (step 1) not when it goes to step 2. How do I stop the default action of the button until the user click's "OK" in the dialogue?

$("#step0Next").live('click', function(event) {
  event.preventDefault();
  if($("#RT").is(":checked") && !$(".ex").is(':checked')) { 
       return confirm ('foo');
       //alert("You have not selected any exchanges for which to receive real time market data from. If you continue, you will only receive real time data for market metrics and ten minute delayed data for everything else. Do you wish to continue?"); 
       $(this).die('click');
  } 
});
A: 

confirm() has no default action. Instead of returning it you need to prevent the default after checking the return value from it. (I'm not completely following your question, but I'm assuming you would want to continue after the user clicks OK ... not "stop the default action"?)

Remove event.preventDefault() from where it is now and do:

if( ... long if statement ... ) {
    if( confirm("Are you sure? Yadda Yadda") ) {
        // User clicked OK 
    }
    else {
        // User clicked Cancel
        event.preventDefault();
    }
}

Of course if you really do want to prevent the default action of whatever was clicked even if the user clicked OK then leave the preventDefault call where it was. The code I provide will still tell you which button they clicked in the confirm dialog.

Cfreak
Not sure I follow, replace the .is(':checked') with the contents of the message? Please clarify
Dirty Bird Design
Looks like the message was edited ... but no the "... long if statement ..." is your if statement (that was changed to is(':checked')) ... the if( confirm ... ) is instead of return confirm()
Cfreak
Sorry for being stupid. I changed from calling the elements by ID to a class to make it shorter. To sum up, if a user clicks the "#step0Next" button to go from step 1 to step 2, I need the function to run (it does now) and if "#RT" is checked and none of the checkboxes with a class of '.ex' are checked, DO NOT go tot step 2 and display the alert/confirm dialogue. I don't see how your code is supossed to work, is it basing the function off of the message? Could you please show an example with either my code or similar, I need to understand this better!
Dirty Bird Design
Ok well I think I don't understand your original question. The function as posted makes it seem like you need to do the reverse. User clicks the button. If the error condition is met (#RT is checked but .ex classes are not checked) then show a confirm dialog. If the user clicks OK then continue. If they click CANCEL then prevent default. Do you need an alert or a confirm because they are two different things. Confirm allows the user a choice, alert just shows the message. My code is an example of how to use confirm and know which button was clicked. Clarify and maybe I can give a better answer
Cfreak
A: 

this didn't work. This did:

<script type="text/javascript">

$("#step0Next").live('click', function(event) { $('#step1Prev').click(); //go back to step 1 if($('#RT').is(':checked') && !$('.ex').is(':checked')) { if(!confirm("You have not selected any exchanges for which to receive real time market data from. If you continue, you will only receive real time data for market metrics and ten minute delayed data for everything else. Do you wish to continue?")) return; $('#step0Next').die('click'); } $(this).triggerHandler('click'); });

Dirty Bird Design