paulb@53 | 1 | function requestUpdate(url, fieldName, targetName, targetFieldName) { |
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@56 | 9 | // Find the value of the target field, along with the node where the target field is defined. |
paulb@56 | 10 | |
paulb@53 | 11 | var targetFieldValue; |
paulb@53 | 12 | var targetFieldNodes = document.getElementsByName(targetFieldName); |
paulb@53 | 13 | if (targetFieldNodes.length != 0) { |
paulb@53 | 14 | targetFieldValue = targetFieldNodes[0].value; |
paulb@53 | 15 | } else { |
paulb@53 | 16 | targetFieldValue = ""; |
paulb@53 | 17 | } |
paulb@56 | 18 | |
paulb@56 | 19 | // Load the remote document with the given parameters sent as text in the request body. |
paulb@56 | 20 | |
paulb@53 | 21 | xmlhttp.send(fieldName + "=" + fieldValue + "\r\ntarget-field-name=" + targetFieldName + "\r\n" + targetFieldName + "=" + targetFieldValue); |
paulb@56 | 22 | |
paulb@56 | 23 | // Parse the result document. |
paulb@56 | 24 | |
paulb@44 | 25 | var newDocument = Sarissa.getDomDocument(); |
paulb@44 | 26 | newDocument.loadXML(xmlhttp.responseText); |
paulb@56 | 27 | |
paulb@56 | 28 | // Find the definition of the affected field in the result document. |
paulb@56 | 29 | |
paulb@47 | 30 | var newElement = newDocument.getElementById(targetName); |
paulb@44 | 31 | var targetElement = document.getElementById(targetName); |
paulb@56 | 32 | |
paulb@56 | 33 | // Insert the new definition into the current document. |
paulb@44 | 34 | |
paulb@44 | 35 | if (newElement != null && targetElement != null) { |
paulb@44 | 36 | var importedElement = document.importNode(newElement, true); |
paulb@44 | 37 | targetElement.parentNode.replaceChild(importedElement, targetElement); |
paulb@44 | 38 | //importedElement.setAttribute("style", "background-color:red;"); |
paulb@44 | 39 | } |
paulb@44 | 40 | } |