$(function() { var documentID = $("#documentID").html(); $("#addAttachment").click(function() { $("#addAttachmentModal").dialog('open'); }); $("#addAttachmentModal").dialog({ autoOpen: false, height: 900, width: 600, modal: true, buttons: { "Add Attachment": function() { var attachmentInputs = $('#DocumentAttachmentAddForm').find('input'); $.post('/documents/saveAttachments', attachmentInputs, function(data) { if(data == 'SUCCESS') { loadAttachments(); $(this).dialog('close'); } else { alert("Attachments could not be saved") } }); }, Cancel: function() { $( this ).dialog( "close" ); } }, close: function() { loadAttachments(); } }); $("#attachmentPrincipleSelect").change(function() { var principleID = $(this).val(); loadPrincipleAttachments(principleID); }); function loadPrincipleAttachments(id) { $.get('/documents/getAttachmentsByPrinciple/'+id, function(attachments) { $('#principleAttachments').html(attachments); }); } function loadAttachments() { $.get('/documents/getAttachments/'+documentID, function(attachments) { }); } });