Solved

auto close confirmation dialog

Posted on 2008-06-22
6
3,553 Views
Last Modified: 2013-11-19
Hi,
I have a confirmation dialog. It is being used to warn the user about a time consuming operation, and confirm that he wants to proceed. The problem is that the dialog window does not close until all the JavaScript on the page stopped executing.

How is it possible to close the dialog window or set a time limit, etc.?

function verify()
{
  var result= confirm("This operation may take up to one minute. Do you want to proceed?");
  if (!result)
  {
    exit();
  }
  
}
//The dialog window is not closed after the function finishes executing. //It is closed only after all javascript on the page stops running.

Open in new window

0
Comment
Question by:msosno
  • 4
6 Comments
 
LVL 63

Expert Comment

by:Zvonko
ID: 21843635
Check this:


function verify(){
  if(confirm("This operation may take up to one minute. Do you want to proceed?")){
     setTimeout("doTheComputation()", 10);
  } else {
     setTimeout("exit()", 10);
  }
}
0
 
LVL 63

Accepted Solution

by:
Zvonko earned 500 total points
ID: 21843643
I do not know your exit() function but perhaps it does not work globaly.
Then check this:

function verify(){
  if(confirm("This operation may take up to one minute. Do you want to proceed?")){
     setTimeout("doTheComputation()", 10);
  } else {
     exit();
  }
}
0
 
LVL 16

Expert Comment

by:Lolly-Ink
ID: 21851373
You can't use the JavaScript confirm method for this. The confirm method stops JavaScript from executing. You'll have to use a floating div element with content to simulate a dialog box. Examples can be found by performing an internet search with tags: JavaScript close alert OR confirm.
0
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 

Author Comment

by:msosno
ID: 21851807
Zvonko: Thanks, everything works.
Is there a way to end script execution?
0
 
LVL 63

Expert Comment

by:Zvonko
ID: 21852984
No, there is not. You can only exit the current function with the return statement. In the return statetement you can pass a return value. Depending on that return value can the calling function do a return exit to the next calling level. But you canot kill the parent calling function execution levels.
http://home.cogeco.ca/~ve3ll/jstutor3.htm
0
 
LVL 63

Expert Comment

by:Zvonko
ID: 21852987
Or short: use return statement to exit the function execution.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question