title: Jquery trap form submit()
body: <p>I'm currently using jquery to trap the submission of a form and show users a dialog for confirmation. If user clicks yes, then form should submit. If user clicks no, then close the dialog. </p>
  
  <p>This all works well but for one issue: when the user clicks yes, this then triggers the same code again, and the dialog is re-opened.</p>
  
  <pre><code>$("#myform").submit(function (event) {
      if (something) {
          var $dialog = $('&lt;div&gt;&lt;/div&gt;').dialog({
              buttons: {
                  "OK": function () {
                      $dialog.dialog('close');
                      $("#myform").submit();
                      return;
                  },
                  Cancel: function () {
                      $(this).dialog("close");
                  }
              }
          });
          $dialog.dialog('open');
          event.preventDefault();
          return false;
      } else {
          $("#myform").submit();
      }
  });
  </code></pre>
  
  <p>I understand why this is happening, just not sure on the best way to get around it. I realise that I could show the modal on button click, instead of form submit, but this doesnt get around the problem of user hitting enter button on keyboard to submit the form.</p>