title: Onclick to submit a form
body: <p>There is a PHP-generated HTML 4 transitional page that is used to edit data from a database of a single record. The user has two options: to store changes or delete the record. I use a form with controls (some of them are hidden):</p>
  
  <pre><code>&lt;form method="post" action="object_mod.php"&gt;&lt;!-- this is another file --&gt;
  &lt;!-- inputs follow --&gt;
  </code></pre>
  
  <p>As I want to process two actions ie. delete or save a record I put two submit buttons on the form, before <code>&lt;/FORM&gt;</code> tag:</p>
  
  <pre><code>&lt;input type="submit" id="btnSubmit" value="Save"&gt;
  &lt;input type="submit" id="btnDelete" value="Delete"&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>Because the user should confirm deletion I added the following <code>onclick</code> event:</p>
  
  <pre><code>&lt;input type="submit" id="btnDelete" value="Delete" onclick="javascript:deleteRecordConfirm();"&gt;
  </code></pre>
  
  <p>(I also tried without <code>javascript:</code> and <code>onclick="javascript:deleteRecordConfirm(); return true;"</code>), but it doesn't submit a form.</p>
  
  <p>The JS function is</p>
  
  <pre><code>function deleteRecordConfirm(){
    if(confirm('Are you sure to delete?')){
      document.getElementById("field_action").value=-1;
      //document.forms[0].submit();
      return true;
    }
  }
  </code></pre>
  
  <p>This <code>field_action</code> is set to -1 so I know in object_mod.php that I want to delete record rather than save it.</p>
  
  <p>Here go question, <em>why this form doesn't submit on deletion</em>?</p>
  
  <p>I think it would be good if a user has Javascript disabled to submit a form anyway, even without confirmation so that is why I use <code>&lt;INPUT TYPE="submit"&gt;</code> for deletion. Is it a good idea? I was thinking about giving two independent forms (in fact deletion should have only one hidden field with record id) with their own submit buttons, one for deletion and the other for saving.</p>
  
  <p>In fact the page will work in some kind of intranet, with users who I trust and I'm not afraid of hacking or something, but any security remarks are also welcome.</p>
  
  <p>(I tested it on Firefox 19.0 and Javascript console shows no errors, w3c validator says it's a valid page).</p>