Click here to Skip to main content
15,879,613 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to close the dialog box on enter key. There are multiple dialogs on the page so making OK button selected work for first dialog but it will not work when another dialog apper and hence I am trying to find way to close any dialog on enter key hit.

function open_errmessage_box()
           modal: true,
           bgiframe: true,
           width: 500,
           height: 300,
           title: document.getElementById("<%=messagebox_title.ClientID%>").value,
           open: function(type, data) {
               $(this).parents('.ui-dialog-buttonpane button:eq(0)').focus();
               $(this).parents('.ui-dialog-buttonpane button:eq(0)').keyup(function(e) {  if (e.keyCode == 13) { $("#duplicateDataMessage").dialog("close"); } });
               $(this).keyup(function(e) { if (e.keyCode == 13) { $("#duplicateDataMessage").dialog("close"); } });
           showDialog: ('#duplicateDataMessage'),
           buttons: {
               'Ok': function() {



This is what I am trying but I am missing something. Can you please suggest some solution ?

$(this).keyup(function(e) { if (e.keyCode == 13) { $("#duplicateDataMessage").dialog("close"); } });

1 solution

Hey, If i were you and this is not working - i'd try to call the .trigger('click') on the actual generated Close button with a selector..

so it would probally be something like
$('#duplicateDataMessage button.close').trigger('click');

else maybe just .hide() it.. :/
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900