|
|||||||
| JavaScript JavaScript (not Java) Discussion and technical support, including AJAX and frameworks (JQuery, MooTools, Prototype...) |
![]() |
|
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
self.location.href wont happen?
Hi!
I have a problem with a javascript and I am hopeing anyone have any suggestions. On one of my pages I have a simple login-form, its not ment to be secure or anything. Once my form was complete and functioning ok, I also wanted the "login" to happen when the enterkey was pressed (instead of having to press a button after typing the password). I cant redirect it to the page with self.location.href. This is my form: Code:
<form> <br> <center> Password: <input type="password" name="password" onKeyPress="Loginb(this,event,this.form);" style="background:#bfbfbf;color:#212121;border-color:#212121;" onFocus="this.style.background = '#ffffff';" onBlur="this.style.background = '#bfbfbf';"> <br> <input type="button" value="Login" onClick="Login(this.form);" style="background:#bfbfbf;color:#000000;border-color:#212121;" onMouseOver="this.style.color = '#404040';" onMouseOut="this.style.color = '#000000';" onFocus="this.style.color = '#404040';" onBlur="this.style.color = '#000000';"> </center> </form> Code:
function Login(form) {
password = new Array("p1","p2","p3","p4");
page = "b" + ".html";
if (form.password.value == password[0] || form.password.value == password[1] || form.password.value == password[2] || form.password.value == password[3]) {
self.location.href = page;
}
else {
alert("Wrong password.\nTry again.");
form.password.focus();
}
return true;
}
function Loginb(myfield,e,form)
{
password = new Array("p1","p2","p3","p4");
page = "b" + ".html";
var keycode;
if (window.event) keycode = window.event.keyCode;
else if (e) keycode = e.which;
else return true;
if (form.password.value == password[0] || form.password.value == password[1] || form.password.value == password[2] || form.password.value == password[3]) {
if (keycode == 13)
{
alert("Login!");
self.location.href = page;
}
}
else
{
if (keycode == 13){
alert("Wrong password.\nTry again.");
form.password.focus();
}
}
return true;
}
Thnx /Danell |
|
#2
|
||||
|
||||
|
Works as expected. Is that the complete document?
__________________
At least 98% of internet users' DNA is identical to that of chimpanzees |
|
#3
|
|||
|
|||
|
hmm, does it work even when you press enter efter typing password (eg. p1)?
for me i got the alert but then nothing. |
|
#4
|
|||
|
|||
|
and no, its not the complete html document. it has a <html> and loads the javascript from a file in the header.
It seems that when I am pressing enter after typing the password the page reloads. |
|
#5
|
|||
|
|||
|
i discovered something!
the line: Code:
if (keycode == 13)
{
alert("Login!");
self.location.href = page;
}
Code:
if (keycode == 13)
{
self.location.href = page;
alert("Login!");
}
This is... well... a complete mystery to me. |
|
#6
|
||||
|
||||
|
pressing the Enter key initiates the submission of the form, his will prevent that
Code:
<form onsubmit="return false;">
__________________
At least 98% of internet users' DNA is identical to that of chimpanzees |
|
#7
|
|||
|
|||
|
perfect!
thanks alot! I guess putting the alert after self.loca... made it to have time to move before the form was submitted! again, thank you! |
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|