I wanna submit the form when pressing down the enter key.
C#
<asp:LinkButton ID="LinkButton1" runat="server" class="login-button" OnClick="btnLogin_Click" >Login</asp:LinkButton>
JS
$(document).on('keydown ', function(event) {
var key = {
submit: event.keycode || event.which
};
if (key.submit == 13) {
document.getElementById('LinkButton1').click();
}
});
Then, I get the error in chrome 18.
Object javascript:__doPostBack(‘LinkButton1’,”) has no method ‘click’
This will do it:
Fiddle
This will call the function which is assigned to your login button’s
onclickhandler when you press the Enter key in your page.The problem you were facing is most likely because your
.click()is a shorthand for.trigger('click')which is not very well supported cross-browser if the handler was assigned outside of jQuery.Also, looking through some answers, this seems to be the simplest way to do this.