Ok, I'm doing a bunch of RIA/AJAX stuff and need to create a "pretty", custom confirm box which is a DIV (not the built-in javascript confirm). I'm having trouble determining how to accomplish a pause in execution to give the user a chance to accept or decline the condition before either resuming or halting execution. (depending upon their answer)
So here's the general flow of logic I'm dealing with:
To demonstrate the logic:
function buttonEventHandler() {
if (condition1) {
if(!showConfirmForCondition1) // want execution to pause while waiting for user response.
return; // discontinue execution
}
if (condition2) {
if (!showConfirmForCondition2) // want execution to pause while waiting for user response.
return; // discontinue execution
}
if (condition3) {
if (!showConfirmForCondition3) // want execution to pause while waiting for user response.
return; // discontinue execution
}
...
}
If anybody has dealt with this challenge before and found a solution, help would be greatly appreciated. As a note, I'm also using the MS Ajax and jQuery libraries although I haven't found any functionality that may already be included in those for this problem.
I'm afraid to say that it's not possible to pause the Javascript runtime in the same way that the "confirm" and "alert" dialogs pause it. To do it with a DIV you're going to have to break up your code into multiple chunks and have the event handler on the custom confirm box call the next section of code.
There have been some projects to bring "continuations" support into Javascript, such as Narrative Javascript so if you're really keen on getting it to work in a single block of code you could look into that.