 <p>Try this JSFiddle that seems to fit your needs <a href="http://jsfiddle.net/9nF5W/" rel="nofollow">http://jsfiddle.net/9nF5W/</a></p> <pre><code>function test(email, name) { if (email == "" || name == "") { alert("Enter mail or name"); return false; } if (email.indexOf("@") == -1) { alert("Bad email"); return false; } var a = email.length; var b = name.length; if (a &gt; 0 &amp;&amp; b &gt; 0) { alert("Message sent"); } return true; } test('tes@t', 'test'); </code></pre> <p>I think there is an other mistake than the returns statements in "<code>if(a==&gt;0, b==&gt;0){</code>" by the way.</p>