Link to home
Start Free TrialLog in
Avatar of ravinesolutions
ravinesolutions

asked on

Javascript change dropdown value to attribute of responseXML AJAX

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

ASKER CERTIFIED SOLUTION
Avatar of BenMorel
BenMorel

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of john4823
john4823

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