Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
141
rated 0 times [  142] [ 1]  / answers: 1 / hits: 57764  / 14 Years ago, fri, march 26, 2010, 12:00:00

In a jquery modal dialog, is there a way to select a button as the default action (action to execute when the user presses enter)?



Example of jquery web site:
jquery dialog modal message



In the example above the dialog closes when the user presses Esc. I would like the Ok button action to be called when the user presses Enter.


More From » jquery

 Answers
73

In your dialog's open function, you can focus the button:



$(#myDialog).dialog({
open: function() {
$(this).parents('.ui-dialog-buttonpane button:eq(0)').focus();
}
});


Change the :eq(0) if it's at a different index, or find by name, etc.


[#97239] Monday, March 22, 2010, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jonrened

Total Points: 627
Total Questions: 114
Total Answers: 99

Location: Zimbabwe
Member since Thu, Jul 21, 2022
2 Years ago
jonrened questions
Mon, Nov 2, 20, 00:00, 4 Years ago
Tue, May 19, 20, 00:00, 4 Years ago
Tue, Jan 21, 20, 00:00, 4 Years ago
Thu, Nov 7, 19, 00:00, 5 Years ago
;