I'm having issues trying to put a simple password protect script in my HTML (I know its not secure, I don't need high level protection) but the redirect function doesn't work.
I'm having trouble with the input:image Onclick action it doesn't redirect to the proper page when the correct password is entered. If I use a input:button then it works but I want to use a input:image. What am I doing wrong? Any help is appreciated.
Here is the Javascript:
<script language="javascript">
<!--//
/*PW Script*/
function pasuser(form) {
if (form.pass.value=="fred") {
window.location="portfolio.html";
}
else {
alert("Please enter the correct Password. Or request one under contacts");
}
}
//-->
</script>
Here is my form to call the Javascript:
<form name="login">
<fieldset>
<div class="LC_field2">
<span class="ghosttext">
<input type="password" name="pass" placeholder="Password">
</span>
</div>
<div class="LC_field3">
<input type="image" border="0" src="images/go_button.png" width="52" height="25" alt="Go" onClick="pasuser(this.form);" />
</fieldset>
</form>
You just have to return false on your onclick event to prevent the default browser behavior for input elements.
onClick="pasuser(document.forms.login); return false;"