Javascript Validation
<p>I was just trying to submit a simple form to the same page but when it is submitted it will call PHP funtion on the same page. However I was trying to do some javascript validation before submission. So I want to know what the difference between using onSubmit call js function in the form tag and onClick call js function with button.... This is what I am currently trying to do.</p>

<pre><code>&lt;?php
  function tobecalled()
  {
    echo "This was run";
  }
?&gt;
&lt;html&gt;
  &lt;head&gt;&lt;title&gt;Testing&lt;/title&gt;
    &lt;script type="text/javascript"&gt;
    function testResults (form) 
    {
      var TestVar = form.inputboxname.value;
      if(TestVar == '')
        return false;
      else
        return true;
    }
    &lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
    &lt;form action="&lt;?php $_SERVER['PHP_SELF'] ?&gt;" method="POST" onSubmit="return testResults(this);"&gt;
      &lt;input type="text" name="inputboxname" /&gt;
      &lt;input type="submit" value="Save" name="submit" /&gt;
      &lt;?php
      if(isset($_POST['submit']))
      tobecalled();
      ?&gt;
    &lt;/form&gt;
  &lt;/body
&lt;/html&gt;
</code></pre>

<p>It works..</p>

<p>But if I make (Submit Via JS)</p>

<pre><code>&lt;form action="&lt;?php $_SERVER['PHP_SELF'] ?&gt;" method="POST"&gt;
  ...
  &lt;input type="submit" value="Save" name="submit" onClick="return testResults(this);"/&gt;
  ...
</code></pre>

<p>Its still calls the PHP function <code>tobecalled()</code>--Why? I am expecting it not call. How do it work?</p>
