How do I get two JavaScript references to the same HTML-form to work?
<p>I'm having trouble validating an HTML form with JavaScript. On their own they each work, but together they don't. </p>

<p><strong>This works:</strong></p>

<pre><code>// Make sure the e-mail address is valid
function validateEmail(mailform,email) { 
    var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
    var address = document.forms[mailform].elements[email].value;
    if(reg.test(address) == false) {
        alert('E-mail not valid');
        return false;
    } 
}
</code></pre>

<p>Attribute in the form:</p>

<pre><code>onsubmit="javascript:return validateEmail('mailform', 'email');"
</code></pre>

<p><strong>And this works:</strong></p>

<pre><code>// Make sure the message is long enough
function validateBody(mailform,mailbody) { 
    var msg = document.forms[mailform].elements[mailbody].value.length;
    if (msg &lt; 3) {
        alert('Too hort');
        return false;
    }
}
</code></pre>

<p>Attribute in the form:</p>

<pre><code>onsubmit="javascript:return validateBody('mailform', 'mailbody');"
</code></pre>

<p><strong>But this doesn't work:</strong></p>

<pre><code>// Make sure the e-mail address is valid AND that the message is long enough
function validateForm(mailform,email,mailbody) { 
    var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
    var address = document.forms[mailform].elements[email].value;
    var msg = document.forms[mailform].elements[mailbody].value.length;
    if(reg.test(address) == false) {
        alert('Please enter a valid e-mail address');
        return false;
    } else if (msg &lt; 3) {
        alert('Text too hort');
        return false;
    }
}
</code></pre>

<p>Attribute in the form:</p>

<pre><code>onsubmit="javascript:return validateForm('mailform', 'email', 'mailbody');"
</code></pre>

<p><strong>Why?</strong></p>

<p>As I said, they work each on their own, but even as different functions, they don't work together.</p>
