I’m trying to submit a form from JavaScript when a user hits the [ENTER] key. .submit won’t work because we have multiple buttons in our form.
The DDLClientName drop down list resides in our aspnetForm form. There is another custom control in this form called SaveCancelDelete. This control (*.ascx) contains all of our buttons.
What I want to do is cause the click event to fire for one of the buttons. What I have below works, but it’s a little hacked up. I tried the code below that with the nested ClientID callbacks, but that doesn’t seem to work. I’m looking for the cleanest approach.
jQuery(this.Elements.DDLClientName).keypress(function(e) {
if (e.keyCode === 13) {
//jQuery("#aspnetForm").submit();
jQuery("#ctl00_body_QuickDataEntryEditor_SaveCancelDelete_BtnNonAuthenticated1").click();
}
});
This doesn’t seem to work:
jQuery('#<%=SaveCancelDelete.ClientID %>').jQuery('#<%=BtnNonAuthenticated1.ClientID %>').click();
Your second example needs to be
.find()instead of.jQuery()but since it’s already an ID, you don’t really need to have both, this should work too: