title: How to close SP.UI.ModalDialog from button click in sharepoint?
body: <p>I want to show Confirmation Dialog when user saves any document from EDITForm.aspx. So I have written following JavaScript code.</p>
  
  <pre><code>function PreSaveAction() {
  
   var _html = document.createElement();
   _html.innerHTML = "  &lt;input  type=\"button\"  value=\"Submit\"    onclick ='javascript:SubmitDlg();'  /&gt;  &lt;input  type=\"button\"  value=\"Cancel\" onclick =\"javascript:CloseDlg();\"     /&gt; &lt;/td&gt;           &lt;/tr&gt;   &lt;/tbody&gt; &lt;/table&gt;";
  
  
   var options = {
              title: "Confirm",
              width: 400,
              height: 200,
              showClose: false,
              allowMaximize: false,
              autoSize: false,
              html: _html           
          };
          SP.UI.ModalDialog.showModalDialog(options); 
  
  }
  
  function SubmitDlg() { 
     SP.UI.ModalDialog.commonModalDialogClose(SP.UI.DialogResult.OK);
  
  
  }
  
  function CloseDlg() {
       SP.UI.ModalDialog.commonModalDialogClose(SP.UI.DialogResult.Cancel);
  }
  </code></pre>
  
  <p>Now I have following queries.</p>
  
  <ol>
  <li>SubmitDlg and CloseDlg is not fired when clicking on Submit or
  Cancel.</li>
  <li>Is this right way to Submit form (SubmitDlg method ) and Cancel dialog (CloseDlg method) from modal dialog ?</li>
  <li>Also this modal dialog-box should be only appeared if no validation errors while saving record, means if any field-value is required and we have not put any value then it should display in-built red colored messages.</li>
  </ol>
  
  <p>Thanks</p>