semi-sentient
08-18-2006, 02:34 PM
I have a situation where I need to halt code execution and wait for feedback (a button click) from the user. I've written a custom dialog class that is designed to replace both alert() and prompt(), but the issue that I'm having is that I'm unable to stop execution when the dialog (basically a div that overlays the page) appears.
Here is some sample code that shows my dialogs usage:
myDialog.show(); // shows the dialog
/* code execution needs to halt at this point */
/* this will NOT work: while(myDialog.getButtonClicked() == "") {} */
// determine which button was clicked and take appropriate action
if (myDialog.getButtonClicked() == "yes") {
// do something
} else {
return;
}
If I write a loop that waits for the button click, browser resources are consumed and no interaction with the dialog is possible, not to mention the browser will give you a message that allows you to stop code execution alltogether.
When using the built-in alert() and prompt() methods, code execution halts until a button is clicked.
This is the same functionality I'm looking for. I'm almost positive that this is not really possible, but I thought I'd ask anyway. It would be fantastic if there was a way to mimic multi-threading in JavaScript, this way I can just loop until I have an appropriate button click, but this seems impossible as well.
Any ideas?
Here is some sample code that shows my dialogs usage:
myDialog.show(); // shows the dialog
/* code execution needs to halt at this point */
/* this will NOT work: while(myDialog.getButtonClicked() == "") {} */
// determine which button was clicked and take appropriate action
if (myDialog.getButtonClicked() == "yes") {
// do something
} else {
return;
}
If I write a loop that waits for the button click, browser resources are consumed and no interaction with the dialog is possible, not to mention the browser will give you a message that allows you to stop code execution alltogether.
When using the built-in alert() and prompt() methods, code execution halts until a button is clicked.
This is the same functionality I'm looking for. I'm almost positive that this is not really possible, but I thought I'd ask anyway. It would be fantastic if there was a way to mimic multi-threading in JavaScript, this way I can just loop until I have an appropriate button click, but this seems impossible as well.
Any ideas?