user1603492
user1603492

Reputation: 13

jQuery Modal dialog onclick

So, I have a link,

<a href="javascript: void(0)" id="dialog_link">I'm the link</a>

and I am trying to get a modal dialog to open up when you click the link, with an accept button, and when you click the accept button, it will forward to a new page. This is the dialog script,

<script>
$(document).ready(function() {
    $('#dialog').dialog({ autoOpen: false })
    $('#dialog_link').click(function(){ 
        $( "#dialog" ).dialog('open', {
            modal:true,
            buttons: {
                Accept: function() {
                    $( this ).dialog( "close" );
                }
            }
        }); 
    });
}); 

For now the accept should just close the box. The problem I am having is that is opens the dialog, but doesn't grab any of the options I specified. Anyone know how to fix it?

Upvotes: 1

Views: 11103

Answers (2)

jgauffin
jgauffin

Reputation: 101192

No need to call dialog first:

$(document).ready(function() {
    $('#dialog_link').click(function(){ 
        $( "#dialog" ).dialog({
            modal:true,
            autoopen: true,
            buttons: {
                Accept: function() {
                    $( this ).dialog( "close" );
                }
            }
        }); 
    });
}); ​

http://jsfiddle.net/HtYQd/

Upvotes: 1

Ohgodwhy
Ohgodwhy

Reputation: 50798

$('#dialog').dialog({ autoOpen: false })
$('#dialog_link').click(function(){
    $( "#dialog" ).dialog({
        modal:true,
        buttons: {
            Accept: function() {
                $( this ).dialog( "close" );
            }
        }
    });
    $('#dialog').dialog('open');
});

Upvotes: 1

Related Questions