Onsubmit gets called on window.onload
<p>first I am not JavaScript expert, just learning, trying to follow some tutorials.
What I would like JavaScript to do is, when form has been submitted do a validation on the fields.</p>

<p>The code I wrote so far gets triggered on page load/reload, which is not desired functionality I am after. From what I understand this formFunction should be called only on onsubmit event.
Guys if you see me something doing wrong please let me know. I would like to build a javascript function that will validate all forms on the page on submit
Here are my JavaScript steps I came up with so far:</p>

<p>1 call checkForms function on window.onload</p>

<pre><code>window.onload=checkForms; 
</code></pre>

<p>2 loop through all forms on the page and add onsubmit listener for the page forms</p>

<pre><code>function checkForms(){
    for(var i=0; i&lt;document.forms.length; i++){
        document.forms[i].onsubmit=thisForm(document.forms[i]);
    }
}
</code></pre>

<p>3 trigger thisForm function on submit</p>

<pre><code>function thisForm(thisForm){
    var elements = thisForm.elements;
    var msg='';
    for(var i=0; i&lt;elements.length; i++){
        msg += elements[i].name +'\n';
    }
    alert(msg);
    // this is where I want to send field values to be validated
}
</code></pre>
