title: how to write javascript code inside php
body: <p>i have a got a form, on clicking the submit button:</p>
  
  <ol>
  <li>I want to do some task in the same file (db task) AND</li>
  <li>I want the form data to be sent to test.php with the redirection</li>
  </ol>
  
  <p>here is my code</p>
  
  <pre><code>    &lt;?php
      if(isset($_POST['btn'])){
          //do some task
      ?&gt;
      &lt;script type="text/javascript"&gt;
          var e = document.getElementById('testForm'); e.action='test.php'; e.submit();&lt;/script&gt;
      &lt;?php
      }
      ?&gt;
  &lt;form name="testForm" id="testForm"  method="POST"  &gt;
      &lt;input type="submit" name="btn" value="submit" autofocus  onclick="return true;"/&gt;
   &lt;/form&gt;
  </code></pre>
  
  <p>but not able to submit the form, if i call the javascript code on onClick, it works.what is the problem in this code, Is there any work around for this </p>