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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T15:41:41+00:00 2026-05-23T15:41:41+00:00

I have some html to popup a jQuery UI modal: <a href=my/url class=popup>Click me</a>

  • 0

I have some html to popup a jQuery UI modal:

<a href="my/url" class="popup">Click me</a>

With this javascript code:

$('.popup').click(function() {
    var a = this;

    var dialog = $('<div>').load($(a).attr('href'), function() {
        var form = dialog.find('form');

        dialog.dialog({
            modal: true,
            title: $(a).attr('title'),
            buttons: {
                Add : function () {
                    $.post($(form).attr('action'), $(form).serialize());
                    dialog.dialog('close');
                },
                Cancel: function () {
                    dialog.dialog('close');
                }
            }
        });

        if ($(a).attr('data-third')) {
            // Add here a button
        }
    });
    return false;
});

The idea is the resource in the modal contains a form, on submit of the modal the form is submitted. Now when <a href="my/url" class="popup" data-third="Add & new">Click me</a> exists, it means a third button is placed in the modal in this order: Cancel | Add | Add & new.

I tried this code:

if($(a).attr('data-third')) {
    var buttons = dialog.dialog('option', 'buttons');
    buttons[$(a).attr('data-third')] = function(){
        // Callback here
    }
    dialog.dialog('option', 'buttons', buttons);
}

I got a new button, but the order is Add & new | Cancel | Add. How can I make sure the order is Cancel | Add | Add & new?

  • 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-23T15:41:42+00:00Added an answer on May 23, 2026 at 3:41 pm

    With this code you should always get Cancel | Add | Add & new? (from left to right.

    $('.popup').click(function() {
        var a = this;
    
        var dialog = $('<div>').load($(a).attr('href'), function() {
            var form = dialog.find('form');
    
            dialog.dialog({
                modal: true,
                title: $(a).attr('title'),
                buttons: {
                    Cancel: function() {
                        dialog.dialog('close');
                    },
                    Add: function() {
                        $.post($(form).attr('action'), $(form).serialize());
                        dialog.dialog('close');
                    }
                }
            });
    
            if ($(a).data('third')) {
                var buttons = dialog.dialog('option', 'buttons');
                console.log(buttons);
                buttons[$(a).data('third')] = function() {
                    // Callback here
                }
                dialog.dialog('option', 'buttons', buttons);
            }
        });
        return false;
    });
    

    Fiddle here: http://jsfiddle.net/rqq2p/1/

    Remember to use data() and not attrib() to get the attribute from the link!

    EDIT – basically “buttons” is an object, and each property is one of the buttons. I think that the order in which the buttons appear is the order in which the properties are added. In my example Cancel is the leftmost button because it was the first added property and add & new it’s the rightmost because it was the latest. If you need to fiddle with the order you could create a new object and add the properties in the order you want:

        if ($(a).data('third')) {
            var buttons = dialog.dialog('option', 'buttons');
            var newButtons = {};
            newButtons[$(a).data('third')] = function() {
                // Callback here
            }
            newButtons['Cancel'] = buttons['Cancel'];
            newButtons['Add'] = buttons['Add'];
            dialog.dialog('option', 'buttons', newButtons);//now add & new should be the leftmost
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have html code block like this <div id=some-div> <a href=# class=link-click>some link text</a>
I have some HTML that looks like this: <div> <div class=value> <a href=# class=clicker>Some
I have some jQuery code like this: // Called right away after someone clicks
I have this as my html; <div data-role=page id=page1> <div data-role=content class=Content> <a href=#popupBasic
Hello I have some HTML that looks like this, <div id=music_interests> <ul class=interests> <li
I have some html like the following: <div class=control-group> <input type=text data-bind=value: $data.DealCode name=DealCode
I'm having some trouble with IE6 and jQuery UI. I have a popup dialog
i have some php files with html code in it and from my php
I have some javascript code that will pass data to a pop up for
I have been using jQuery prettyPhoto plugin to show inline html content. This content

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.