title: How do I get a JQuery statement to wait until it's completed before continuing?>
body: <p>Firstly, I'm new at Javascript / Jquery so it might be a stupid question...</p>
  
  <p>I'm using the dialog box that is in the JQuery UI collection. I have a button that when clicked, it either shows a confirm box or an alert box. My code is like below...</p>
  
  <pre><code>            function checkfn() {
  
              if (document.getElementById('&lt;%=HomeInstSelected.ClientID%&gt;').value == 'False') {
  
                  var dialogResult = false;
  
                  $("#dialog-confirm").dialog({
                      resizable: false,
                      height: 140,
                      modal: true,
                      buttons: {
                          Continue: function () {
                              dialogResult = true;
                              $(this).dialog("close");
  
                          },
                          Cancel: function () {
                              $(this).dialog("close").slideUp();
                          }
                      }
                  });
  
                  // alert just debug code!
                  alert(dialogResult);
                  return dialogResult;
  
              }
              else {
                  $("#dialog-HomeInstitutionPrompt").dialog({
                      height: 140,
                      modal: true
                  });
  
              } 
          }
  </code></pre>
  
  <p>My problem is in the confirm part, it seems the confirm box is not waiting for me to hit Continue or Cancel - it's just going straight to the alert part and returning dialogResult = false.</p>
  
  <p>Is it possible to halt execution of until after I've run the $('#dialog-confirm') command?</p>
  
  <p>Alternatively, is it possible to return true for the checkfn() function, in the Continue function? That way, I will not need a dialogResult var at all?</p>