Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simple Jquery Dialog but now on click

I tried making a dialog using jquery it works but I have no succes at doing it onclick bacuse it should not just popup but only when you click on it.

<script type="text/javascript"> 
$.ui.dialog.defaults.bgiframe = true;
$(function() {
    $("#dialog").dialog();
});
</script>  

and

<div id="dialog" title="Basic dialog">
    <p>hi how are you</p>
</div>

and for the nice looking button

<button id="create-user" class="ui-button ui-state-default ui-corner-all">Profiel Matthijs</button>

tried using these examples

http://jqueryui.com/demos/dialog/
http://jqueryui.com/demos/dialog/#modal-form

anyone know how to get this working with an click on the #create-user button i am not so good at javascript.

Thanks Matthy

like image 729
matthy Avatar asked Jul 30 '09 00:07

matthy


1 Answers

You need to set the autoOpen option to false so that the dialog will not open when its created.

To open it when your button is clicked, you would call the open method.

<script type="text/javascript"> 
    $.ui.dialog.defaults.bgiframe = true;
    $(function() {
        $('#dialog').dialog({
            autoOpen: false
        });
        $('#create-user').click(function() {
            $('#dialog').dialog('open');
        });
    });
</script>
like image 146
Ken Browning Avatar answered Oct 21 '22 03:10

Ken Browning