Click here to Skip to main content
15,908,111 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I have two dropdownlists.
On selection of the first one,second one gets populated.
The below code works fine in IE.
But not in other browser.
Is there any workaround for other browsers?
This function changeService() is called on the indexchange of the first dropdown.

function changeService(cntrlCampus)
	{ 
	   var _scampus =  cntrlCampus.value;
	   var service = document.getElementById("ctl00_cphContentSection_hdnservice").value;
	   var age = document.getElementById("ctl00_cphContentSection_hdnAge").value;	 
	   var xmlDoc = new ActiveXObject("Msxml2.DOMDocument");
	   xmlDoc.async = false;	
		var configxmlPath = '<%= ConfigurationManager.AppSettings["servicespath"].ToString()%>';
		var requestUrl=configxmlPath + 'Services.xml';
         
         //Clear all service drop down values.
         document.getElementById("ctl00_cphContentSection_patientservicemajor").options.length = 0;
         var opnCode = "";
		 var opnValue = "-Select-"
		 var opnText = document.createElement("option");
		 document.getElementById("ctl00_cphContentSection_patientservicemajor").options.add(opnText);
		 opnText.text = opnValue;
		 opnText.value = opnCode;		          
		 document.getElementById("ctl00_cphContentSection_hdnmandatoryservice").value = "false";
	    xmlDoc.load(configxmlPath + 'Services.xml');
		
		
		   if(xmlDoc != null)
		   {
		        var serNodeList = '';       
		
		        if(age >=18)
                    serNodeList = xmlDoc.selectNodes("//major/Services[@campus='"+_scampus+"' and @regtype='"+service+"']");                                        
		        else
		            serNodeList = xmlDoc.selectNodes("//minor/Services[@campus='"+_scampus+"' and @regtype='"+service+"']");
		        if(serNodeList != null)
		        {		  
		            if(serNodeList.length>0)
		            {        
		                for(var i=0;i<sernodelist.length;i++)>
		                {
		                    var opnCode = serNodeList[i].getAttribute("name");
		                    var opnValue = serNodeList[i].getAttribute("text");
		                    var opnText = document.createElement("option");
		                    document.getElementById("ctl00_cphContentSection_patientservicemajor").options.add(opnText);
		                    opnText.text = opnValue;
		                    opnText.value = opnCode;
		                } 
		                DisplayMandatory('hidemandservice');
		            }
		            else
		            {
		                document.getElementById("ctl00_cphContentSection_hdnmandatoryservice").value = "true";
		                HideMandatory('hidemandservice');
		            }
		        } 		         
		    }
		 
	}
Posted
Updated 30-Apr-11 7:10am
v2
Comments
thatraja 30-Apr-11 13:11pm    
which browser? Did you check firefox error console for any error message? If you find anything just update your question with those things.

1 solution

hi,

I think var xmlDoc = new ActiveXObject("Msxml2.DOMDocument"); will only work with IE. Here is an example to load XML that work with IE, Mozilla, Safari, Opera etc.

http://www.justin-cook.com/wp/2006/11/03/how-to-load-xml-data-with-javascript-ajax-tutorial/[^]

As an alternative, you also can use jQuery to load the XML and access the node value. If you are interested, I wrote an article a while ago which use jQuery to load and read the XML file. Here is the link to it.

http://blog.ysatech.com/post/2009/11/10/ASP-NET-slideshow-Control-with-jQuery-and-XML.aspx[^]
 
Share this answer
 
Comments
avishekrc 1-May-11 11:39am    
Hi Brian,
As per your suggestion,I have tried the first link for IE only.
Please find below my modified changeService() function.
However,xmlhttp.readyState is giving the value 1.
What can be the reason?
<pre>var xmlhttp='';
function changeService(cntrlCampus)
{ debugger;
var _scampus = cntrlCampus.value;
var service = document.getElementById("ctl00_cphContentSection_hdnservice").value;
var age = document.getElementById("ctl00_cphContentSection_hdnAge").value;
var configxmlPath = 'http://localhost:2753/PatientPortal_MH/MemberForms/xml/';
var requestUrl=configxmlPath + 'Services.xml';


xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
if (xmlhttp)
{
//xmlhttp.onreadystatechange = xmlhttpChange(age,_scampus,service);
xmlhttp.open("GET", "requestUrl", true);
xmlhttp.onreadystatechange= function test()
{
if (xmlhttp.readyState==4)
{
alert(xmlhttp.responseText);
}
xmlhttp.send(null);
}
}
}</pre>
Thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900