We help IT Professionals succeed at work.

Javascript change dropdown value to attribute of responseXML AJAX

ravinesolutions
on
I need to change the value of a dropdown to the value that comes from an AJAX called PHP script.

I try this two ways and both ways work in FF but not IE:


xmlDoc = xmlHttp.responseXML;
	
	alert(xmlHttp.responseText);
	
	var line = xmlDoc.getElementsByTagName("line")[0];
 
	//document.getElementById('o_contact_type1').value = line.attributes['type'].value;
	
	var type = line.attributes['type'];
	var o_contact_type1 = document.getElementById('o_contact_type1');
	o_contact_type1.options[o_contact_type1.options.length] = new Option(type.text,type.value);

Open in new window

Comment
Watch Question

Commented:
Hi, try this :

var type = line.getAttribute('type');

Regards,
Ben

Commented:
Cannot alert the right value - tried your idea also. This is just a test run.

var title = line.attributes[1].nodeValue;
      xmlHttp = new XMLHttpRequest();
      xmlHttp.open("GET", "secured/get_ids.php?title=" + title, false);
      xmlHttp.send(null);      
      var xmlDoc2 = xmlHttp.responseXML;
      var element2 = xmlDoc2.getElementsByTagName('doc2').item(0);   // Read the first element
      var line2 = element2.getElementsByTagName('line2').item(0);
      alert(line2.attributes[0].nodeValue);

Please suggest why this throws up an error in IE7.
Cheers

Explore More ContentExplore courses, solutions, and other research materials related to this topic.