jsFiddle , jQueryUI ( , , - , , , ).
/ JavaScript:
var theDialog = $("<div id='msg'>");
theDialog.append("<div><label for='txtVal'>Enter a Value:</label><input type='text' id='txtVal'/></div>");
Then I use the jQuery UI dialog dialog to create an instance of the modal display and display it. I also collect information about this and pass it back (parent).
Hope this is what you want to do. Please let me know if there are other questions and I will update my answer accordingly.
Hope this helps!
CODE
By the way, this is not optimized - this is purely for demonstration purposes. Do not use in production!
HTML:
<div id="content">
<span>Click here for the modal:<button id="openModal">Open</button></span>
<br/>
<span>Results:<input id="theResults" type="text" />
</div>
JavaScript:
$(document).ready(function() {
$("#openModal").click(function(e) {
e.preventDefault();
openDialog();
});
});
function openDialog() {
var theDialog = $("<div id='msg'>");
theDialog.append("<div><label for='txtVal'>Enter a Value:</label><input type='text' id='txtVal'/></div>");
$(theDialog).dialog({
title: "Sample Dialog",
modal: true,
buttons: { "Cancel": function() {
$(this).dialog("destroy");
$("#msg").remove();
},
"Save": function() {
$("#theResults").empty();
$("#theResults").val($("#txtVal").val());
$(this).dialog("destroy");
$("#msg").remove();
}
}
});
}
source
share