title: How to pause and resume javascript?
body: <p>I want to pause the javascript code below after it calls $('#dialog').dialog('open'); and until user responds this dialog box. I used while loop but it stops all the javascript. I just want to pause this function. Any ideas? </p>
  
  <p><strong>Note: I dont want to split my code into two functions. I just want to pause javascript until the user enters some values, like a prompt</strong></p>
  
  <pre><code>function sendSubComment(button){
  form = button.parentNode
  nodes= form.elements;
  cmt = $(nodes.item(0)).val();
  cmt = cmt.replace(/\n/g,"&lt;br&gt;");
  title = $(nodes.item(1)).val();
  for(i=0;i &lt; nodes.length;i++){
      nodes.item(i).disabled = 'true';
  }
  c = form.parentNode.parentNode;
  if(checkUserLogin() == false){
      $('#dialog').dialog('open');
       //pause starts here
       //return the values of user
       //resume javascript
  }
  document.title = c.id;
  $.post('index/phplibrary/action.php',{cmd:'insert_comment',cmt:cmt,title:title,id_topic:&lt;?php echo $GLOBALS['id_topic']; ?&gt;,id_parentComment:c.id,subcomment:'1'},function(result){
          $.post('ajax/comments.php?cmd=get_subcomment&amp;id_subcomment='+result,function(res){
                  extendMakeComment(form);
  
                  node = c.childNodes[3];
                  document.title = node.className;
                  t = document.createElement("DIV");
                  t.innerHTML = res;
                  t = t.childNodes[0];
                  $(t).hide();        
                  node.appendChild(t);
                  $(t).show("slow");
                  form.reset();
                  for(i=0;i &lt; nodes.length;i++){
                      nodes.item(i).disabled = '';
                  }
              });
  
      });
  </code></pre>
  
  <p>}</p>
  
  <p>this code is how i create dialog box</p>
  
  <pre><code>$('#dialog').dialog({
  autoOpen: false,
  width: 600,
  buttons: {
      "Ok": function() { 
          $(this).dialog("close"); 
      }, 
      "Cancel": function() { 
          $(this).dialog("close"); 
      } 
  }
  });
  </code></pre>