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 6810479
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:12:38+00:00 2026-05-26T20:12:38+00:00

Following up from this question , I’m trying to implement an unobtrusive confirm dialog.

  • 0

Following up from this question, I’m trying to implement an unobtrusive confirm dialog.

$(document).ready(function () {
    $("[data-confirmPrompt]").click(function (event) {
        var confirmPrompt = event.currentTarget.attributes['data-confirmPrompt'].value;
        event.preventDefault();
        $.prompt(confirmPrompt, {
            buttons: { Yes: true, No: false },
            callback: function (v, m, f) {
                if (v) {
                    // User clicked Yes.  Unbind handler to avoid
                    // recursion, then click the target element again
                    $(event.currentTarget).unbind('click');
                    event.currentTarget.click();
                }
            }
        });
    });
});

When the user has clicked on “Yes”, I want the default action associated with the event to execute. I’ve done it above by unbinding the jQuery handler, and clicking the element again. This works fine when submitting a form or navigating to a different page – but of course does not work in AJAX-enabled pages, where I want to keep the jQuery event handler.

Is there an alternative generic way to execute the default action? Logically something like event.executeDefault().

  • 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-05-26T20:12:39+00:00Added an answer on May 26, 2026 at 8:12 pm

    Using the suggestion Alexey Lebedev made in his second comment, my current implementation now looks like the sample below, except that I’ve also added my own implementation of localization for the button labels.

    Notes:

    • I’m now using a jqueryUI dialog widget
    • Note the use of .delegate so that the handler is “ajax-aware”, i.e. works on elements added to the DOM after the page is loaded, e.g. as a result of an AJAX call
    • Uses a flag to prevent recursion when the user clicks Yes on the confirm dialog.
    • Uses jquery 1.6.4 and jquery-ui-1.8.16

    If anyone can suggest improvements, please chime in.

    <!-- Examples of usage -->
    <input type='submit' data-confirm="OK to delete customer 123?" ... />
    <a href="..." data-confirm="OK to navigate?" ... />
    
    <!-- Implementation -->
    <script type="text/javascript">
        var confirmClickHandler = function (event) {
            if ($(event.currentTarget).data('isConfirming')) return;
            var message = event.currentTarget.attributes['data-confirm'].value;
            event.preventDefault();
            $('<div></div>')
                    .html(message)
                    .dialog({
                        title: "Confirm",
                        buttons: {
                            "Yes": function () {
                                $(this).dialog("close");
                                $(event.currentTarget).data('isConfirming', true);
                                event.currentTarget.click();
                                $(event.currentTarget).data('isConfirming', null);
                            },
                            "No": function () {
                                $(this).dialog("close");
                            }
                        },
                        modal: true,
                        resizable: false,
                        closeOnEscape: true
                    });
        };
    
        $(document).ready(function () {
            $("body").delegate("[data-confirm]", "click", confirmClickHandler);
        });
    </script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Following on from this question...I'm trying to unit test the following scenario: I have
Check this example before reading the question - http://www.sqlfiddle.com/#!2/fcf3e/8 The following data comes from
Following on from this previous question: Linq query for EF 4.1 data with nested
So following on from this question: Erlang lists:index_of function? I have the following code
Following from this OS-agnostic question , specifically this response , similar to data available
Following on from this question , I am interested in finding out how you
following on from this question (Developing to an interface with TDD), I'm still having
Following on from this question... What to do when you’ve really screwed up the
Following the CSS style trick from this question I was able to create a
Following this question, it seems that it is possible to open a file from

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.