The below code is used to access a webpage I called myPage.html by entering a password of 1234. Once the password is entered the User either clicks the Login Button or presses the "Enter" key.

Clicking the login button works OK. My problem is that I have to press the Enter key twice for it to go to myPage.html

What do I need to change so I only have to press the Enter key once?


function TheLogin() {
var password = '1234';
if (this.document.login.pass.value == password) {
top.location.href="http://myPage.html";}
}

</script>
<p align="center">
<p align="center"><br>
<p align="center"><font size="5"><b><font color="#000000">Please enter the Password to Enter</font></b></font><br>
<p>&nbsp; </p>
<center>Enter your password:<br>
<form name="login" style="margin: 0px">


<INPUT TYPE="password" NAME="pass" size="17" onKeyDown="if(event.keyCode==13) event.keyCode=9;" style="width: 152px; margin: 5px;"><br>

<input type="button" value="Click to Login" style="width : 150px; margin: 3px" onClick="TheLogin(this.form)">
</form>
</center>

Make '<input type="submit"' instead of '<input type="button"'...

Also why are you doing this login with JavaScript and not PHP?

Remember that a visitor can read your javascript...
not exactly secure, is it/

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.