fgui fgui - 7 months ago 55
jQuery Question

jquery-ui Dialog: Make a button in the dialog the default action (Enter key)

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.

Answer Source

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

    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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download