title: Change form submit action and then submit the form
body: <p>I'm trying to add a button to my form that would essentially run some different php code than my regular form submission code, that would, instead of emailing me the form, convert my page into a nice pdf ready to print. I have everything working except that pressing the button is giving me an error.</p>
  
  <p>Firebug says :
  <img src="https://i.stack.imgur.com/BmrTJ.png" alt="enter image description here"></p>
  
  <p>Here's the code:</p>
  
  <pre><code>&lt;form id="adaugareanunt" name="adaugareanunt" action="mailerPDF.php" method="post"&gt;
      &lt;table width="535" border="0" cellspacing="2" cellpadding="3"&gt;
           &lt;tr class="TrDark"&gt;
           //... more form code
  </code></pre>
  
  <p>and for the button:</p>
  
  <pre><code>&lt;div style="text-align:right"&gt;&lt;img src="images/print-button.png" onClick="chgAction()" width="60px" height="20px"&gt;&lt;/div&gt;
  </code></pre>
  
  <p>with the script:</p>
  
  <pre><code>&lt;script language="JavaScript" type="text/JavaScript"&gt;
      function chgAction()
          {
              document.getElementById["adaugareanunt"].action = "mailerXFDF.php";
              document.getElementById["adaugareanunt"].submit();
              document.getElementById["adaugareanunt"].action = "mailerPDF.php";
  
          }
  &lt;/script&gt;
  </code></pre>