 <p>Make the first function call the next one and add this to your HTML :</p> <pre><code> &lt;input&gt; type=button onclick="validateForm(); return false;" &lt;/input&gt; </code></pre> <p>Putting 'return false' will prevent redirection and will give time for your function to execute.</p> <pre><code>function validateForm(){ var email = document.forms["form"]["Email"].value; if(email == null || email == ""){ alert("Email must be filled out"); return false; } else redirect(); } </code></pre> <p>Additionally, I'd recommend to abstain from putting any code in your HTML. It is considered a "bad practice". However, if you still want to put your code, it'll be more appropriate to put it in the form as an "onsubmit" action:</p> <pre><code>&lt;form onsubmit="validateForm()"&gt; </code></pre> <p>If you want the function to execute when the submit button is clicked, you can just add an event listener in your script and an id to your button, like this:</p> <pre><code>var button = document.getElementById("submit"); button.onclick = function validateForm() { /*same code as above..*/ }; </code></pre> <p>Hope it helps!</p>