title: Simple JavaScript login form validation
body: <p>Just a really simple login and redirect, but the script doesn't fire since I changed the button input type to 'submit' and the onClick event to onSubmit. All is does now is just add the username and password as a string to the url.    </p>
  
  <pre><code>&lt;form name="loginform"&gt;
      &lt;label&gt;User name&lt;/label&gt;
      &lt;input type="text" name="usr" placeholder="username"&gt; 
      &lt;label&gt;Password&lt;/label&gt;
      &lt;input type="password" name="pword" placeholder="password"&gt;
      &lt;input type="submit" value="Login" onSubmit="validateForm();" /&gt;
  &lt;/form&gt;
  
  &lt;script&gt;
      function validateForm() {
          var un = document.loginform.usr.value;
          var pw = document.loginform.pword.value;
          var username = "username"; 
          var password = "password";
          if ((un == username) &amp;&amp; (pw == password)) {
              window.location = "main.html";
              return false;
          }
          else {
              alert ("Login was unsuccessful, please check your username and password");
          }
        }
  &lt;/script&gt;
  </code></pre>