read xml in javascript problem
- by Najmi
hai all,
i have a problem with my code to read the xml.I have use ajax to read xml data and populate it in combobox. My problem is it only read the first data.Here is my code
my xml like this
<area>
<code>1</code>
<name>area1</name>
</area>
<area>
<code>2</code>
<name>area2</name>
</area>
and my javascript
if(http.readyState == 4 && http.status == 200) {
//get select elements
var item = document.ProblemMaintenanceForm.elements["probArea"];
//empty combobox
item.options.length = 0;
//read xml data from action file
var test = http.responseXML.getElementsByTagName("area");
alert(test.length);
for ( var i=0; i < test.length; i++ ){
var tests = test[i];
item.options[item.options.length] = new Option(tests.getElementsByTagName("name")[i].childNodes[i].nodeValue,tests.getElementsByTagName("code")[i].childNodes[i].nodeValue);
}
}