I think you misunderstand the dialog usage.
Setting the dialog will automatically hide it with it option to not automatically open it.
Just set this attribute to not open automatically:
autoOpen: false
See these changes for example: comments in code
var comment = ""; //global to hold comment text
$(document).ready(function() {// put in a document ready handler
$("#diaMissedPU").dialog({
modal: true,
autoOpen: false,
draggable: false,
closeOnEscape: true,
title: "Missed P/U Comments ",
resizable: false,
width: 380,
buttons: {
Ok: function() {
var mycomments = $("input#diaMissedPucomments");//save to reuse
comment = mycomments.val();//get value
alert("comment : " + comment);
viewname = "CIMtrek_Compliance_Daily_Shipments_Case_Pack_Update_MissedPUs";
//callHome(viewname,comment);
mycomments.val("");// clear value
$(this).dialog('close');
}
},
close: function(event, ui) {// use this or not, just to illustrate
alert(comment);
}
});
$("#wackme").click(function() {// button to activate your function
openMissedPUComments();
alert("commentbefore : " + comment); //NOTE: runs before dialog closes
});
});
function openMissedPUComments() {
var selectedValues = "";
comment = "";//clear value in variable
$('input:checked').each(function() {
selectedValues = $(this).val() + "," + selectedValues;
});
if (selectedValues.length == 0 && selectedValues == "") {
alert("To run this agent you must have at least one document selected");
return false;
} else {
$("#diaMissedPU").dialog("open");
}
}
sample working :http://jsfiddle.net/Hw6ZA/