 <p>I highly recommend you to use jQuery or a proper JavaScript validator library for your form. Here is a simple example of how you can validate an input field with jQuery.</p> <p>HTML part:</p> <pre><code>&lt;input type="text" id="username"&gt; &lt;input type="button" id="sendForm" value="send"&gt; &lt;p id="usernameError"&gt;&lt;/p&gt; </code></pre> <p>jQuery part:</p> <pre><code>$(function () { $('#sendForm').on("click", function () { validateUserForm(); }); }); function validateUserForm() { var username = $('#username').val(); if (username == '') { $('#usernameError').html('Please insert your username!'); } else { $('#usernameError').html(''); } } </code></pre> <p>And here is a functional jsFiddle: <a href="https://jsfiddle.net/1bk3ufhd/" rel="nofollow">https://jsfiddle.net/1bk3ufhd/</a></p>