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