Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8259523
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T02:53:04+00:00 2026-06-08T02:53:04+00:00

I took the JQuery UI dialog form sample from JQuery UI website. Since I

  • 0

I took the JQuery UI dialog form sample from JQuery UI website.

Since I wanted that, once the dialog is opened and the form is displayed, that pressing the key submits the form, I added the following in the onReady() :

$.extend($.ui.dialog.prototype.options, {
open: function() {
var $this = $(this);

      // focus first button and bind enter to it
      $this.parent().find('.ui-dialog-buttonpane button:first').focus();
      $this.keypress(function(e) {
          if( e.keyCode == 13 ) {
              $this.parent().find('.ui-dialog-buttonpane button:first').click();
              return false;
          }
      });
  } 

});

This does perfectly the trick (I mean the click() is triggered when it has to), but the following occurs :

When the form is first submited through a press on the key, the submission is performed once.

If I reopen the dialog, and submit it again with a press on the key, the form is submitted twice.

If I reopen the dialog, and submit it again with a press on the key, the form is submitted three times, and so on…

This can be tested with the following fiddle :
http://jsfiddle.net/fWW2E/

Let me add that doing so by clicking on the dedicated “Submit” button works properly, this fails only when pressing the key is involved.

Any ideas ?

Thank you !

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T02:53:07+00:00Added an answer on June 8, 2026 at 2:53 am

    Because since you’re assigning this on “open” and your buttons are “closing” the dialog.

    When this gets called though:

    $('something').dialog('close');

    doesn’t actually remove the element, it just hides it. So the next time you click to open up a “new” dialog, you’re really just showing the first one again. However the “open” event is getting fired again every time it’s opened, which is adding a new keypress handler onto it.

    Here’s the fiddle. I actually write out to the console an array of the current handlers on that element. You’ll see everytime you open the dialog that there is another keypress handler.

    DEMO

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using backbone.js, underscore.js and jQuery. I took the following sample code from http://jsfiddle.net/thomas/C9wew/6/
I saw some jquery code on the Net somewhere, that took this form :
i just took the demo jquery UI dialog (model dialog) sample and tried to
Recently, i am working with jquery for my mini-project. I took a code from
Trying to learn jquery here so I took a regular javascript snippet that loops
So I recently took a closer look at JavaScript and jQuery and after that
I wanted to do something like Wordpress editor. I took jQuery UI tabs (I
I took a snapshot of the jquery.js file and jquery-ui files that I use
Im using the JqueryUI modal form and since im new to Jquery I figured
it took me some time to find out that both Eclipse and Aptana get

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.