read xml in javascript problem

Posted by Najmi on Stack Overflow See other posts from Stack Overflow or by Najmi
Published on 2010-05-15T03:04:41Z Indexed on 2010/05/15 3:14 UTC
Read the original article Hit count: 242

Filed under:
|
|

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);


                             }


                     }

© Stack Overflow or respective owner

Related posts about AJAX

Related posts about Xml