what is meant by 'dialogOpen' flag here is determining whether user opened the dialog box, selected some types and clicked 'Done' button. Coz in both Done and Cancel button it calls the close as jQuery(this).dialog("close"); . However we only need to disply the selected types if the close() option came from 'Done' button. That is what i check here.