title: Login in and registration function in Javascript not working
body: <p>I'm trying to make a simple registration and login function in Javascript. I want to have 6 input elements and 2 buttons in the html code. </p>
  
  <p>(Login Section) 1 input for username, 1 for password and 1 button for running the login function. </p>
  
  <p>(Registration section) 1 for new username, 1 for new email, one for new password , 1 for repeat password and 1 button for running the registration function. </p>
  
  <p>First, a user fills in the registration fields, if a field is empty, alert "fill the field"s, else if new password is different from repet password, password and repet password dont match, else, alert you are registered. Here i want new password and new username to be saved in new password and use it in the login section.</p>
  
  <p>Second, a user knows what the new password and new username is and can loggin.
  if, username is logged in, alert you are in, else if username and password is the same as new username and new password, alert you are logged in, redirect to index.html.</p>
  
  <p>This is what i have done so far.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>var username = document.form.username.value;
  var newusername = document.form.newusername.value;
  var password = document.form.password.value;
  var newpassword = document.form.newregpw.value;
  var newregemail = document.form.newregemail.value;
  var loggedin = "outside";
  
      function login() {
          if (loggedin == "inside") {
              alert("You are already on the inside. Go shopping!");
          } else if (username == newusername &amp;&amp; password == newregpw) {
              loggedin = "inside";
              window.location = "index.html";
              alert("Logged in, go shopping!");
          } else {
              alert("Wrong Username or Password. Try again.");
          }
      }
  
      function reg() {
          if (newusername === null || newregemail === null || newregpw === null || reppw === null) {
              alert("Fill out all the fields.");
          } else if (newregpw != reppw) {
              alert("The password and repet password field dosen't match. Try again!");
          } else {
              alert("Congraulations you are now registerd");
          }
      }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.6/jquery-ui.min.js"&gt;&lt;/script&gt;
  &lt;script src="script.js"&gt;
      
  &lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;div id="content"&gt;
          &lt;div id="navbar"&gt;
              &lt;ul&gt;
                  &lt;li&gt;&lt;a href="index.html" class="one"&gt;HOME&lt;/a&gt;
                  &lt;/li&gt;
                  &lt;li&gt;&lt;a href="about.html" class="one"&gt;ABOUT&lt;/a&gt;
                  &lt;/li&gt;
                  &lt;li&gt;&lt;a href="contact.html" class="one"&gt;CONTACT&lt;/a&gt;
                  &lt;/li&gt;
                  &lt;li&gt;&lt;a href="account.html" class="one"&gt;ACCOUNT&lt;/a&gt;
                  &lt;/li&gt;
                  &lt;li&gt;&lt;a href="login.html" class="one"&gt;LOGIN&lt;/a&gt;
                  &lt;/li&gt;
              &lt;/ul&gt;
          &lt;/div&gt; &lt;a href="index.html"&gt;
       &lt;div id="header"&gt;
       &lt;/div&gt;
      &lt;/a&gt;
  
          &lt;div id="menu-clothes"&gt;
              &lt;ul&gt;
                  &lt;li class="menu-class"&gt;&lt;a href="category.html" class="one"&gt;MEN&lt;/a&gt;
                  &lt;/li&gt;
                  &lt;li class="menu-class"&gt;&lt;a href="category.html" class="one"&gt;WOMEN&lt;/a&gt;
                  &lt;/li&gt;
                  &lt;li class="menu-class"&gt;&lt;a href="category.html" class="one"&gt;CHILDREN&lt;/a&gt;
                  &lt;/li&gt;
              &lt;/ul&gt;
          &lt;/div&gt;
          &lt;div id="account"&gt;
              &lt;!-- Login och skapa ny medlem funktionen --&gt;
               &lt;h4&gt;Login/New account&lt;/h4&gt;
  
               &lt;h5&gt;Login&lt;/h5&gt;
  
               &lt;h6&gt;Usernamn/E-mail&lt;/h6&gt;
  
              &lt;form name="login"&gt;
                  &lt;input type="text" name="username" id="username" required/&gt;
                   &lt;h6&gt;Password&lt;/h6&gt;
  
                  &lt;input type="password" name="password" id="password" required/&gt;
                   &lt;h6&gt;Login&lt;/h6&gt;
  
                  &lt;input type="button" name="login" value="Login" id="login" onClick="login()" /&gt;
                   &lt;h5&gt;New Account&lt;/h5&gt;
  
                   &lt;h6&gt;Choose Username&lt;/h6&gt;
  
                  &lt;input type="text" name="newusername" id="newusername" /&gt;
                   &lt;h6&gt;Enter E-mail&lt;/h6&gt;
  
                  &lt;input type="email" name="newregemail" id="newregemail" /&gt;
                   &lt;h6&gt;Choose Password&lt;/h6&gt;
  
                  &lt;input type="password" name="newpassword" id="newregpw" /&gt;
                   &lt;h6&gt;Repet Password&lt;/h6&gt;
  
                  &lt;input type="password" name="repetpassword" id="repregpw" /&gt;
                   &lt;h6&gt;Complete Registration&lt;/h6&gt;
  
                  &lt;input type="button" name="register" value="Register" id="register" onClick="reg()" /&gt;
              &lt;/form&gt;
          &lt;/div&gt;
          &lt;div id="footer"&gt;
              &lt;ul&gt;
                  &lt;li class="footer-class"&gt;&lt;a href="index.html" class="one"&gt;HOME&lt;/a&gt;
                  &lt;/li&gt;
                  &lt;li class="footer-class"&gt;&lt;a href="about.html" class="one"&gt;ABOUT&lt;/a&gt;
                  &lt;/li&gt;
                  &lt;li class="footer-class"&gt;&lt;a href="contact.html" class="one"&gt;CONTACT&lt;/a&gt;
                  &lt;/li&gt;
              &lt;/ul&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  &lt;/body&gt;
  
  &lt;/html&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>It seems like nothing is happening and i don't really understand why. </p>
  
  <p>If you know any easier way of doing it or if you know what's wrong with the code i would appreciate it a lot! </p>
  
  <p>Kind/Best Regards
  Anton</p>