HTML
CSS
JAVASCRIPT
BOOTTRICK
LATEST BLOG
CODE SHARE
JSON VIEWER
LATEST JOBS
Online Training
Display checkboxes in jQuery UI dialogs
User
HTML
<!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>jQuery UI Dialog -How to add checkbox</title> <link rel="stylesheet" href="https://code.jquery.com/ui/1.13.1/themes/base/jquery-ui.css"> <script src="https://code.jquery.com/jquery-3.6.0.js"></script> <script src="https://code.jquery.com/ui/1.13.1/jquery-ui.js"></script> </head> <body> <input type="button" id="btnOpenDialog" value="Open Confirm Dialog" /> <div id="dialog-confirm">Don't write better error messages, write code that doesn't need them</div> </body> </html>
CSS
#dialog-confirm { display:none } .shut-up { float:left; display: inline-block; margin-top: 1em; }
JavaScript
function fnOpenNormalDialog() { // Define the Dialog and its properties. $("#dialog-confirm").dialog({ resizable: false, modal: true, title: "Modal", height: 250, width: 400, create: function (e, ui) { var pane = $(this).dialog("widget").find(".ui-dialog-buttonpane") $("<label class='shut-up' ><input type='checkbox'/> Oo Really!</label>").prependTo(pane) }, buttons: { "Yes": function () { $(this).dialog('close'); callback(true); }, "No": function () { $(this).dialog('close'); callback(false); } } }); } $('#btnOpenDialog').click(fnOpenNormalDialog); $(document).on("change", ".shut-up input", function () { alert("shut up! " + this.checked) }) function callback(value) { if (value) { alert("Confirmed"); } else { alert("Rejected"); } }