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

  • Home
  • SEARCH
  • 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 7850425
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T18:50:46+00:00 2026-06-02T18:50:46+00:00

I don’t know much about writing good javascript so perhaps I am thinking about

  • 0

I don’t know much about writing good javascript so perhaps I am thinking about this in the wrong way, but here is the situation.

I have a page which contains various plugins, each with an edit button.

So there is for example an HTML plugin, a Twitter plugin etc.

Once you click on the edit button a jQuery UI dialog box is displayed via a common function which all of the edit buttons call.
The content of the dialog is filled with that particular plugin’s update form.

The dialog created by this common function also provides a “Save” and a “Cancel” button automatically.

Since both of these “Save” and “Cancel” buttons are created by the dialog they are both assigned closures to the “click” option.

What I want to do, if possible, is provide some sort of hook function which can be run when the “Save” button is clicked, which can be defined by the javascript in each of the plugin’s update forms.

I think I have explained enough now so here is some sample code:

This would tell each of the edit buttons to create a dialog box and fill it with the appropriate content.

// This function is called by each edit button
// on a click event which passes the required ids

function update_form_dialog(plugin_id) {
    $.post(
        '/get_plugin_update_form',
        {
            'plugin_id': plugin_id
        },
        function(response) {
            var dialog = $('<div class="update_form"></div>').appendTo('body');

            dialog.dialog({
                open: function() {
                    dialog.html(response);
                },
                show: 'fade',
                modal: true,
                title: 'Update plugin',
                width: 'auto',
                height: 'auto',
                buttons: [
                    {
                        text: 'Save',
                        click: function() {
                            // Call a hook defined in the plugin update
                            // form then send update data
                        }
                    },
                    {
                        text: 'Cancel',
                        click: function() {
                            // Close the dialog here
                        }
                    }
                ]
            });
        }
    );
}

As you can see in the above code what I have is pretty simple, but I don’t know how I can add a hook to the start of the “Save” button’s click function.

Each plugin’s update form is stored in the response variable and that is where the plugin update form’s javascript is written.

Is there a way that I can tell the save button what to do before it runs its normal code when the “Save” button is clicked?

If anyone needs more explanation please let me know.

Any help on how I could write this would be much appreciated.

Edit:

It seems I’m having trouble explaining my problem so hopefully this edit will help make things clearer.

What I want is to execute some code which would be optionally defined in the content of the dialog box when it has been opened. This code, if defined, should be executed once the save button is clicked but before the actual click function is executed. Is this possible?

  • 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-02T18:50:48+00:00Added an answer on June 2, 2026 at 6:50 pm

    You can use a plugin for subscribing and attaching to some events like:

    http://weblog.bocoup.com/publishsubscribe-with-jquery-custom-events/
    http://archive.plugins.jquery.com/project/jQuerySubscribe
    http://www.novasoftware.com/download/jquery/publish-subscribe.aspx

    This way, on the save you can publish that the save has been done and all subscribers code will be executed.

    with the third link you can do something like the following:

    $(document).ready(function(){ $('.save').subscribe('save',function(){//dosomething;}})
    

    Later on the save code you can do this:

    $.publish('save');
    

    And the code will be executed
    hope it helps.

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

Sidebar

Related Questions

don't know better title for this, but here's my code. I have class user
Don't need to do this right now but thinking about the future... What would
Don't know how to google for such, but is there a way to query
I don't know whether this is really possible, but I'm trying my best. If
I don't want to know a way to preload images, I found much on
(Don't know if this is strictly on-topic, but I don't see any better Stack
I don't know: if this works. if it's a good idea. what it is
I don't know if this question is trivial or not. But after a couple
Don't know much about running a function on every item in an array, still
Don't know a better title but here is what im trying to do. I

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.