1 function requestUpdate(url, fieldName, targetName, targetFieldNames, elementPath) { 2 3 // Note that XMLHttpRequest access may be denied if Mozilla believes that 4 // this resource's URL and the supplied URL are different. 5 6 var xmlhttp = new XMLHttpRequest(); 7 xmlhttp.open("POST", url, false); 8 9 // Find the value of the controlling field. 10 11 var fieldValue = document.getElementsByName(fieldName)[0].value; 12 13 // Process each target field name. 14 15 var targetFieldNameArray = targetFieldNames.split(","); 16 17 // Send the controlling field value. 18 19 var requestBody = (fieldName + "=" + fieldValue); 20 21 // Add the values of the dependent fields. 22 23 for (var i = 0; i < targetFieldNameArray.length; i++) { 24 var targetFieldName = targetFieldNameArray[i]; 25 26 // Find the values of the target field. 27 28 var targetFieldValue; 29 var targetFieldNodes = document.getElementsByName(targetFieldName); 30 for (var v = 0; v < targetFieldNodes.length; v++) { 31 targetFieldValue = targetFieldNodes[v].value; 32 requestBody += ("\r\n" + targetFieldName + "=" + targetFieldValue); 33 } 34 } 35 36 // Add the element path specification. 37 38 requestBody += ("\r\nelement-path=" + elementPath); 39 40 // Load the remote document with the given parameters sent as text in the request body. 41 42 xmlhttp.send(requestBody); 43 44 // Parse the result document. 45 46 var newDocument = Sarissa.getDomDocument(); 47 newDocument = (new DOMParser()).parseFromString(xmlhttp.responseText, "text/xml"); 48 49 // Find the definition of the affected field in the result document. 50 51 var newElement = newDocument.getElementById(targetName); 52 var targetElement = document.getElementById(targetName); 53 54 // Insert the new definition into the current document. 55 56 if (newElement != null && targetElement != null) { 57 var importedElement = document.importNode(newElement, true); 58 targetElement.parentNode.replaceChild(importedElement, targetElement); 59 //importedElement.setAttribute("style", "background-color:red;"); 60 } 61 }