Sunday, March 31, 2013

jQuery Modal Popups : Adding Ok, Cancel buttons

We need to add Ok, Cancel etc like any other buttons on the modal pop-up : just add them to the buttons array.


buttons: {
                    Ok: function() { alert("you pressed ok"); },
                    Cancel: function() { alert("you pressed cancel"); },
                    Close: function() { alert("Closing the dialog!"); $(this).dialog("close"); }
}

Full Code:



<head runat="server">
    <title></title>
    <script src="jquery-1.9.1.js" type="text/javascript"></script>
    <script src="jquery-1.10.2-ui.js" type="text/javascript"></script>
    <link href="jquery-1.10.2-ui.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript">
        $(function() {
            $("#mydlg").dialog(
            {
                buttons: {
                    Ok: function() { alert("you pressed ok"); },
                    Cancel: function() { alert("you pressed cancel"); },
                    Close: function() { alert("Closing the dialog!"); $(this).dialog("close"); }
                }
            }
            );
            $("#mybtn").click(function() {
                $("#mydlg").dialog();
            });
        });
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div id="mydlg">
    </div>
    <button type="button" id="mybtn">
    </button>
    </form>
</body>

No comments:

Post a Comment

How to check local and global angular versions

 Use the command ng version (or ng v ) to find the version of Angular CLI in the current folder. Run it outside of the Angular project, to f...