I have this button which submits the login form:
<input class="btn btn-large btn-success" id="login-button" onclick="handleLogin()" name="submit" type="submit" value="Login"/>
And I have this function which I want to use to have a custom submit when the user presses enter:
$(document).ready(function () {
$(document).keyup(function(event) {
if(event.which == 13) {
$('#login-button').click();
//event.preventDefault();
//return false;
}
});
});
However this doesn’t do anything at all. I have tried with and without the commented part of the code.
Note that the submission of the form works when clicking and that I don’t have my input fields inside form element. I am using handleLogin() to submit using AJAX. So all I really want is this #login-button to get clicked! Do you guys see the problem? Thanks in advance.
UPDATE: I’m using Chrome BETA channel.
IMPORTANT!: I want #login-button to get clicked when pressing ENTER. Nothing more that that. I already know how to submit a form.
demo fiddle
use:
keyCodeinstead ofwhichuse:
.submit()with thenameoridof your form. http://api.jquery.com/submit/You were missing a
});