Jack Marquies Jack Marquies - 3 months ago 14
Javascript Question

Creating modal dialog with jquery

When someone clicks my label, i want to open a small "Alert" like element, and i want to be able to use the modal's buttons functionality.

Is there a jquery library / extension that can easily do something like this?

$(document).on('click', '#MyLabel', function() {

openModal();

});

Answer

This a fundamentally simple task in jQuery UI. See jsfiddle

$("#myDialog").dialog({
    autoOpen  : false,
    modal     : true,
    title     : "A Dialog Box",
    buttons   : {
              'OK' : function() {
                  var textValue = $('#myTextBox').val();
                  alert('The value of the text box is ' + textValue);
                  //Now you have the value of the textbox, you can do something with it, maybe an AJAX call to your server!
              },
              'Close' : function() {
                  alert('The Close button was clicked');
                  $(this).dialog('close');
              }
                }
});
Comments