1

I have the following problem. I'm trying to add dynamic buttons in a modal dialog with iframe. I have Iframe dialog box with standard buttons (like close, ok..). After new content is loaded by iframe url scr attribute, i need dynamic add new button, for example "register". My code:

var iDlg= $('<iframe src=price.php?code="'+uCode+'" frameborder="0" />').dialog({
                modal: true,
                dialogClass: 'priceBox',
                title: 'Detail',        
                height: 400,
                width: 500,
                draggable: false,
                resizable: false,
                //show: "fade",
                buttons: {
                "close": function() {
                    $( this ).dialog( "close" );
                }
            }       
            }).width(480);

source of price.php:

<script type="text/javascript">
    $(document).ready(function(){
        var opt = {
            buttons: {
                'New button...': function () {
                    $(this).dialog('close');
                }
            }
        };
        $(iDlg).dialog('option', opt);


    });
    </script>

But, this solution doesn't work. Please help. Thanks.

2
  • Could be a typo but it says .iDlg instead of iDlg. Also, is that variable accessible from where you use it? Commented Mar 8, 2012 at 8:04
  • Same :( iDlg is not defined (error in price.php) Commented Mar 8, 2012 at 13:39

2 Answers 2

3

You have to tell it what option you're passing in. In this case, you are passing values for the "buttons" option:

$(document).ready(function(){
   var btns = {
       'New button...': function () {
            $(this).dialog('close');
        }
    };
    iDlg.dialog('option', 'buttons', btns);
});
Sign up to request clarification or add additional context in comments.

Comments

0

In price.php, have you tried passing opt to a function in the parent, i.e., parent.addButton(opt);

Then in the parent frame you'd have

function addButton(opt)
{
    $(iDlg).dialog('option', opt);
}

Of course, iDlg needs to have the correct scope (global) in the parent.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.