title: How to redirect to another page using javascript after successful login?
body: <p>I need to have a login form that validates and after login the page needs to redirect to a html page. I also need to hard code in a username and password so only with the correct user name/password the page will redirect. If it doesn't have the correct user/pass then I need an alert. </p>
  
  <p>I've tried a bunch of variations but I know I missing something or using the code wrong. Please help! :) Thanks!
  This is my code so far. </p>
  
  <p>JS:</p>
  
  <pre><code>function validateForm() {
      'use strict';
  
      // Get references to the form elements:
      var email = document.getElementById('email');
      var password = document.getElementById('password');
  
      // Validate the login
      if ((email.value.length &gt; 0) &amp;&amp; (password.value.length &gt; 0)) {
          return true;
      } else {
          alert('Please complete the form!');
          return false;
      }
  }
  
  function check(form) {
  
      var emailArray = ("myemail@live.com", "");
      var passwordArray = ("MyLogIn", "");
  
      if (email.value == "email" &amp;&amp; password.value == "password") {
          window.open('myaccount.html');
      } else {
          alert('Please enter correct username or password!');
          return false;
      }   
  }
  
  function init() {
      'use strict';
  
      // Confirm that document.getElementById() can be used:
      if (document &amp;&amp; document.getElementById) {
          var loginForm = document.getElementById('lgform');
          loginForm.onsubmit = validateForm;
      }
  }
  window.onload = init;
  </code></pre>
  
  <p>HTML:</p>
  
  <pre><code>&lt;form action="" method="post" id="lgform"&gt;
      &lt;fieldset&gt;
          &lt;legend&gt;Login&lt;/legend&gt;
          &lt;div&gt;
              &lt;label for="email"&gt;Email Address&lt;/label&gt;
              &lt;input type="email" name="email" id="email" required&gt;
          &lt;/div&gt;
          &lt;div&gt;
              &lt;label for="password"&gt;Password&lt;/label&gt;
              &lt;input type="password" name="password" id="password" required&gt;
          &lt;/div&gt;
          &lt;div&gt;
              &lt;label for="submit"&gt;&lt;/label&gt;
              &lt;input type="submit" value="Login" id="submit"&gt;
          &lt;/div&gt;
      &lt;/fieldset&gt;
  &lt;/form&gt;
  </code></pre>