how to associate enter to Login button? Help!
Hi,
I'm adding the login/password fields and a button as part of my home page. The scenario would be the same as your login in the webdeveloper.com website. User just need to give login/password and then press "Enter" key and no need to click the Login button.
I wonder is that done in Javascript? I currently use
function entsub()
{
if(window.event && window.event.keyCode == 13)
{
document.forms[0].page_action.value = "login";
document.forms[0].submit();
}
else
{
return true;
}
}
but that only works for IE, not for firefox. I'm sure there's a much better way out there. Can someone give me some advice or post the code there? Really appreciate that.
Joaquin
[820 byte] By [
jfernandez] at [2007-11-19 20:41:06]

# 1 Re: how to associate enter to Login button? Help!
Well, you are very close. You have two options.
1. Use onkeypress with keyCode == 13.
2. Use a hidden submit button. This is your better option.
style="display:none"
# 2 Re: how to associate enter to Login button? Help!
thanks. got it working with the following,
function screenkey(e) {
var whichCode;
whichCode = (window.Event) ? e.which : e.keyCode;
if ( whichCode == "13" ) {
abort_submit = true;
whichCode = null;
}
}
# 3 Re: how to associate enter to Login button? Help!
thanks. got it working with the following,
Just remember that if JavaScript is disabled, yours will not work. I think that you should think about using the hidden submit button.
# 5 Re: how to associate enter to Login button? Help!
how hidden button works? Can you post a simple snippet of code?
Just use style="display:none".
<input type="submit" value="Submit" style="display:none">