title: Navigate to a url when a correct password is entered in an html form using Js
body: <p>I'm trying to find a way to navigate to a url when a user enters the right password in my form, and display an error alert if they enter the wrong one. I'm a complete newbie to js and used these two links: <a href="https://stackoverflow.com/questions/12784215/password-correct-then-redirect">Password correct? then redirect</a> &amp; <a href="https://stackoverflow.com/questions/13071967/adding-an-onclick-function-to-go-to-url-in-javascript">Adding an onclick function to go to url in javascript?</a> to put my current code together. My current code is:</p>
  
  <pre><code>                    &lt;form class="hero-form"&gt;
                      &lt;fieldset&gt;
                      &lt;div class="row-fluid"&gt;
                          &lt;label&gt;Enter your passcode&lt;/label&gt;
                          &lt;input type="password" name="password" maxlength="8"      class="span7" id="password" placeholder="e.g. 12345678" required/&gt;
                          &lt;button class="btn btn-info btn-large span5" id="joe_btn" input type="submit" value="Submit" onclick="if (document.getElementById('password').value == '12345678') location.href = 'http://example.url.here'; else alert('Please check your passcode and try again');"&gt;Enter&lt;/button&gt;
  
                      &lt;/div&gt;    
                      &lt;/fieldset&gt;
                  &lt;/form&gt;
  </code></pre>
  
  <p>So far I can get it to return an alert if the password is correct, but as soon as I replace:</p>
  
  <pre><code>alert('congrats, correct password')
  </code></pre>
  
  <p>with this it doesn't work.:</p>
  
  <pre><code>location.href = 'http://your.url.here'
  </code></pre>
  
  <p>Any help would be grately appreciated. Please post the full code for your response, as I'm an absolute beginner with js and could easily miss something out if you only post snippets.</p>
  
  <p>Thanks heaps,</p>