title: How to show validation message below each textbox using jQuery?
body: <p>I am trying to make a login form in which I have email address and password as the textbox. I have done the validation on the email address part so that it should have proper email address and also on the empty check both for email address and password text box.</p>
  <p>Here is my <a href="https://jsfiddle.net/aoksoh69/5/" rel="nofollow noreferrer">jsfiddle</a>.</p>
  <p>As of now, I have added an alert box saying, <code>Invalid</code> if email address and password textbox is empty. Instead of that, I would like to show a simple message just below each text box saying , please enter your email address or password if they are empty?</p>
  <p>Just like it has been done here on <a href="https://www.sitepoint.com/basic-jquery-form-validation-tutorial/" rel="nofollow noreferrer">sitepoint blog</a>.</p>
  <p>Is this possible to do in my current HTML form?</p>
  <p><strong>Update:-</strong></p>
  <pre><code>&lt;body&gt;
  
      &lt;div id=&quot;login&quot;&gt;
  
          &lt;h2&gt;
              &lt;span class=&quot;fontawesome-lock&quot;&gt;&lt;/span&gt;Sign In
          &lt;/h2&gt;
  
          &lt;form action=&quot;login&quot; method=&quot;POST&quot;&gt;
              &lt;fieldset&gt;
                  &lt;p&gt;
                      &lt;label for=&quot;email&quot;&gt;E-mail address&lt;/label&gt;
                  &lt;/p&gt;
                  &lt;p&gt;
                      &lt;input type=&quot;email&quot; id=&quot;email&quot; name=&quot;email&quot;&gt;
                  &lt;/p&gt;
                  &lt;p&gt;
                      &lt;label for=&quot;password&quot;&gt;Password&lt;/label&gt;
                  &lt;/p&gt;
                  &lt;p&gt;
                      &lt;input type=&quot;password&quot; name=&quot;password&quot; id=&quot;password&quot;&gt;
                  &lt;/p&gt;
                  &lt;p&gt;
                      &lt;input type=&quot;submit&quot; value=&quot;Sign In&quot;&gt;
                  &lt;/p&gt;
  
              &lt;/fieldset&gt;
  
          &lt;/form&gt;
  
      &lt;/div&gt;
      &lt;!-- end login --&gt;
  
  &lt;/body&gt;
  </code></pre>
  <p>And my JS -</p>
  <pre><code>&lt;script&gt;
      $(document).ready(function() {
          $('form').on('submit', function (e) {
              e.preventDefault();
  
              if (!$('#email').val()) {
                  if ($(&quot;#email&quot;).parent().next(&quot;.validation&quot;).length == 0) // only add if not added
                  {
                      $(&quot;#email&quot;).parent().after(&quot;&lt;div class='validation' style='color:red;margin-bottom: 20px;'&gt;Please enter email address&lt;/div&gt;&quot;);
                  }
              } else {
                  $(&quot;#email&quot;).parent().next(&quot;.validation&quot;).remove(); // remove it
              }
              if (!$('#password').val()) {
                  if ($(&quot;#password&quot;).parent().next(&quot;.validation&quot;).length == 0) // only add if not added
                  {
                      $(&quot;#password&quot;).parent().after(&quot;&lt;div class='validation' style='color:red;margin-bottom: 20px;'&gt;Please enter password&lt;/div&gt;&quot;);
  
                  }
              } else {
                  $(&quot;#password&quot;).parent().next(&quot;.validation&quot;).remove(); // remove it
              }
          }); 
      });
  
  &lt;/script&gt;
  </code></pre>
  <p>I am working with JSP and Servlets so as soon as I click Sign In button, it was taking me to another page with valid email and password earlier but now nothing is happening after I click Sign In button with valid email and password.</p>
  <p>Any thoughts what could be wrong?</p>