I have a following XML document
// I may add two or more text nodes in future
In the aspx file I have a autocomplete textbox(tbauto) which will display the contenets of the 'text' node of 'fault' element. Below this autocomplete textbox I have a normal textbox(tbname).Till this I have no problem.
Now what I want is
if I select a 'Pending Fault found on' option from the autocomplete popup then, I want the 'select_value' attribute's value (i.e.,'Pending fault' ) of the first text node to be displayed on the textbox(tbname). if I select a 'Repaired Fault on' option from the autocomplete popup then, I want the 'select_value' attribute's value (i.e.,'Already repaired' ) of the second text node to be displayed on the textbox(tbname), and so on.
I have a following javascript function (in this function I want to know how to get the data from XML and use it instead of hardcoding )
function SetFaultAction(popupValue) {
// here the popupValue is the value selected in the textbox(according to my XML template its either 'Pending Fault found on' or 'Repaired Fault on')
var pendingFault = "Pending fault";
var repairedfault = "Already repaired";
if (popupValue.search(/Pending/i) > -1) {
document.getElementById('tbname').value = pendingFault;
}
else if (popupValue.search(/repaired/i)> -1){
document.getElementById('tbname').value = repairedfault;
}
the above javascript works fine. (But if I add two more text nodes under the fault element then the above javascript function will not work for those two newly added nodes). But what I want is, the values should be read from XML instead of hardcoding like popupValue.search(/Pending/i) > -1) and var pendingFault = "Pending fault";
Thanks,
Sachi
sachi vasishtaPosted Nov 28, 2011, 9:14 AM
Now I am able to load the XML file. But what I want is, I want to loop through the all elements of the XML document and while doing so if the text node value matches the popValue (for example if popValue='Pending Fault found on') then it should pick its corresponding attribute's value ('Pending fault').
This is what I have done so for.
function SetFaultAction(popupValue) {
if (window.XMLHttpRequest)
{
xhttp=new XMLHttpRequest();
}
else
{
xhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xhttp.open("GET","AutoComplete.xml",false);
xhttp.send();
xmlDoc=xhttp.responseXML;
xmlObj=xmlDoc.documentElement;
var i=0;
for(i=0;i
if (popupValue.search(/xmlObj.childNodes(i).firstChild.text/i) > -1) {
document.getElementById('tbname').value = xmlObj.childNodes(i).getAttribute("selected_value");
}
}
}
but this is returning null in the textbox (tbname) instead of returning 'Pending fault'. I think I have gone wrong with the for loop or with the if condition inside the for loop.
Please help.
Thanks,
Sachi