title: How to do simple client-side form validation using JavaScript/jQuery?
body: <p>I was doing a project series on CodeCademy and I got a project in the series to do a client side form validation using JavaScript/jQuery.</p>
  
  <p>My HTML is:</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;title&gt;Form Validation&lt;/title&gt;
    &lt;link rel='stylesheet' href='stylesheet.css' type='text/css'/&gt;
    &lt;script type='text/javascript' src='script.js'&gt;&lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
   &lt;form&gt;
    First Name : &lt;input type='text' id='fname' placeholder='Enter First Name'&gt;&lt;br&gt;&lt;br&gt;
    Last Name : &lt;input type='text' id='lname' placeholder='Enter Last Name'&gt;&lt;br&gt;&lt;br&gt;
    Age : &lt;input type='text' id='age' placeholder='Age'&gt;&lt;br&gt;&lt;br&gt;
    Sex : &lt;input type='radio' class='sex'&gt; Male &lt;input type='radio' class='sex'&gt; Female
   &lt;/form&gt;
   &lt;button id='submit'&gt;Submit&lt;/button&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>My JavaScript/jQuery is:</p>
  
  <pre><code>$(document).ready(function()
  {
   var fname = document.getElementById('fname').val();
   var lname = document.getElementById('lname').val();
   var age = document.getElementById('age').val();
   /*Do not know how to get element by class and that too, two different type. Have to check if user chose anything or not*/
  
    $("#submit").click(function()
    {
     if(fname.length === 0)
     {
      alert("Please input a first name");
     }
     else if(lname.length === 0)
     {
      alert("Please input a last name");
     }
     else if(age.length === 0)
     {
      alert("Please input an age");
     }
    });
  });
  </code></pre>
  
  <p>I don't need a very complicated code and please help me in the HTML department if something is wrong there or if something needs to be added there. </p>
  
  <p>Also, I don't know how to get different elements in a class. I have put a comment in my jQuery regarding that so please help if you can. </p>
  
  <p>This is a problem in a CodeCademy project and this is where a lot of newbies in JS and jQuery have a problem, so if you can help, it'll help a lot of people and not just me.</p>
  
  <p>Thanks!</p>