I have a handler to catch the event of an "enter" inside a set of inputs in the context of an authentication function, but it's not working when I press the key. The code is as follows :
$('#login form').submit(function(e) { login(e); });
function login(e)
{
e.preventDefault();
var l = $('#logo a').attr('href');
var name = $('#login input[name="login_username"]').val();
var pass = $('#login input[name="login_password"]').val();
$.ajax({
type: 'POST',
url: l+'user/login',
data: 'username='+name+'&password='+pass,
cache: false,
dataType: 'json',
success: function(response)
{
if (response.status == true)
window.location = response.redirect;
else
jQuery.facebox('<p class="facebox-notice">'+response.error+'</p>');
}
});
}
It does work, however, to the button I have for the same purpose :
$('#dologin').click(function(e) { login(e); });
Any ideas why? Cheers!
EDIT
The markup is as follows :
<div id="login">
<form action="" method="post">
<input type="text" name="login_username" />
<input type="password" name="login_password" />
<a href="" id="dologin">LOGIN</a>
</form>
</div>
#login? Where do you attach the key handler to? What does it do? Please add this part too. What do you mean by not working?loginis not called?$('#login form').submit(login);, it'll get the same parameters as any anonymous function, so you'll get the event you want, same goes for.click(login).<input type="submit">button? Users with JS disabled won't be able to use your site. (still missing how you attach the key event handler and what it does)