title: js validation of not null field
body: <p>I have done a login page. I want my js validateForm()function to alert a user if they have left out the username or password. This is the code I have got at the moment.</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;script&gt;
  function validateForm()
  {
  var x=document.forms["myForm"]["username"].value;
  if (x==null || x=="")
    {
    alert("Please enter username");
    return false;
    }
  }
  &lt;/script&gt;
  &lt;/head&gt;
  &lt;div class="users form"&gt;
  &lt;br&gt;
  
  
  &lt;form name="myform" action="Employees/login" onsubmit="return validateForm()" method="post" &gt;
  &lt;?php
  
      if (isset($error)) {
  
  
      echo "&lt;p style='color:red;font-size: 20px''&gt;Username or Password is invalid. Please try again.&lt;/p&gt;";
  
  
          }?&gt;
          &lt;p&gt;Enter Username:
          &lt;input type="text" name="username" placeholder="username" style="height: 25px;width: 160px;"/&gt;&lt;/p&gt;
          &lt;br&gt;&lt;br&gt;
          &lt;p&gt;Enter Password:
          &lt;input type="password" name="password"  placeholder="password" style="height: 25px;width: 160px;"/&gt;&lt;/p&gt;
          &lt;br&gt;
          &lt;input type="submit" style="height:35px;width:100px;font-size: 18px; align:center;" value="Sign in"&gt;
  
     &lt;/form&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>At the moment it is not working, and I think the problem is with the code line "var x=document.forms["myForm"]["username"].value;" Can someone please help?</p>