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

 using Microsoft.AspNetCore.Mvc; using System.Xml.Linq; using System.Xml.XPath; //<table class="common-table medium js-table js-stre...