title: Why won't my JavaScript account system code work or run?
body: <p>I'm trying to create a JS account system with HTML forms, but my script either won't run, or doesn't work. I've looked through the code many times and make changes, but nothing ever works. Can someone help me? Also, this system has one public password, but I could change it to be passwords for everyone. This isn't published, it is just a file that I have, and it would be on two different files, but for this I put them on the same HTML file.</p>
  <pre><code>&lt;form name=&quot;login&quot; onsubmit=&quot;login()&quot;&gt;
              &lt;fieldset style=&quot;width:300px&quot;&gt;
                  &lt;legend&gt;Login&lt;/legend&gt;
                  &lt;label for=&quot;username&quot;&gt;Username:&lt;/label&gt;
                  &lt;br&gt;
                  &lt;input type=&quot;text&quot;
                  name=&quot;username&quot;
                  required&gt;
                  &lt;br&gt;&lt;br&gt;
                  &lt;label for=&quot;password&quot;&gt;Password:&lt;/label&gt;
                  &lt;br&gt;
                  &lt;input type=&quot;text&quot;
                  name=&quot;password&quot;
                  required&gt;
                  &lt;br&gt;&lt;br&gt;
                  &lt;input type=&quot;submit&quot;
                  name=&quot;submit&quot;&gt;
              &lt;/fieldset&gt;
          &lt;/form&gt;
          &lt;script&gt;
              function login() {
                  let usernameinput = document.forms[&quot;login&quot;][&quot;username&quot;].value;
                  let passwordinput = document.fomrs[&quot;login&quot;][&quot;password&quot;].value;
                  var users = [&quot;user123&quot;, &quot;otheruser123&quot;];
                  if (usernameinput == users) {
                      if (passwordinput == &quot;password123&quot;) {
                          alert(&quot;Logged in&quot;);
                          window.location.replace(&quot;home.html&quot;);
                      } else {
                          alert(&quot;Incorrect username and/or password&quot;);
                      }
                  } else {
                      alert(&quot;Incorrect username and/or password&quot;);
                  }
              }
          &lt;/script&gt;
  </code></pre>
  <p>I've tried changing it so that instead of two if functions, there is just one with both inputs and an and operator like this:</p>
  <pre><code>if (usernameinput == users &amp;&amp; passwordinput == &quot;password123&quot;) {
      alert(&quot;Logged in&quot;);
      window.location.replace(&quot;home.html&quot;);
  } else {
      alert(&quot;Incorrect username and/or password&quot;);
  }
  </code></pre>
  <p>I have also tried just putting in usernames instead of the <code>users</code> variable like this:</p>
  <pre><code>if (usernameinput == &quot;user123&quot; || usernameinput == &quot;otheruser123&quot; &amp;&amp; passwordinput == 
  &quot;password123&quot;) {
      alert(&quot;Logged in&quot;);
      window.location.replace(&quot;home.html&quot;);
  }
  </code></pre>
  <p>The last thing I tried was instead of the <code>usernameinput</code> and <code>passwordinput</code> variables, I tried using <code>document.login.username.value</code> or <code>document.login.password.value</code> like this:</p>
  <pre><code>if (document.login.username.value == &quot;user123&quot; &amp;&amp; document.login.password.value == 
  &quot;password123&quot;) {
      alert(&quot;Logged in&quot;);
      window.location.replace(&quot;home.html&quot;);
  }
  </code></pre>
  <p>With this, I also tried it with two if functions. I have no idea why none of this is working.</p>