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: Password correct? then redirect & Adding an onclick function to go to url in javascript? to put my current code together. My current code is:
<form class="hero-form">
<fieldset>
<div class="row-fluid">
<label>Enter your passcode</label>
<input type="password" name="password" maxlength="8" class="span7" id="password" placeholder="e.g. 12345678" required/>
<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');">Enter</button>
</div>
</fieldset>
</form>
So far I can get it to return an alert if the password is correct, but as soon as I replace:
alert('congrats, correct password')
with this it doesn't work.:
location.href = 'http://your.url.here'
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.
Thanks heaps,