dflow Posted December 27, 2009 Share Posted December 27, 2009 i have this script works with all browsers but ie6 <script language="javascript" type="text/javascript"> // Roshan's Ajax dropdown code with php // This notice must stay intact for legal use // Copyright reserved to Roshan Bhattarai - nepaliboy007@yahoo.com // If you have any problem contact me at http://roshanbh.com.np function getXMLHTTP() { //fuction to return the xml http object var xmlhttp=false; try{ xmlhttp=new XMLHttpRequest(); } catch(e) { try{ xmlhttp= new ActiveXObject("Microsoft.XMLHTTP"); } catch(e){ try{ xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); } catch(e1){ xmlhttp=false; } } } return xmlhttp; } function getState(CategoryId) { var strURL="findState2.php?CatID="+CategoryId; var req = getXMLHTTP(); if (req) { req.onreadystatechange = function() { if (req.readyState == 4) { // only if "OK" if (req.status == 200) { document.getElementById('statediv').innerHTML=req.responseText; } else { alert("There was a problem while using XMLHTTP:\n" + req.statusText); } } } req.open("GET", strURL, true); req.send(null); } } function getCity(CategoryId,stateId) { var strURL="findCity2.php?CatID="+CategoryId+"&CountryID="+stateId; var req = getXMLHTTP(); if (req) { req.onreadystatechange = function() { if (req.readyState == 4) { // only if "OK" if (req.status == 200) { document.getElementById('citydiv').innerHTML=req.responseText; } else { alert("There was a problem while using XMLHTTP:\n" + req.statusText); } } } req.open("GET", strURL, true); req.send(null); } } </script> and it is supposed to be triggered by <select name="CatID" onChange="getState(this.value)"> Quote Link to comment Share on other sites More sharing options...
rajivgonsalves Posted December 27, 2009 Share Posted December 27, 2009 I think you might have a javascript error try this for the trigger <select name="CatID" onChange="getState(this[this.selectedIndex].value)"> Quote Link to comment Share on other sites More sharing options...
dflow Posted December 27, 2009 Author Share Posted December 27, 2009 I think you might have a javascript error try this for the trigger <select name="CatID" onChange="getState(this[this.selectedIndex].value)"> still isnt triggered in ie6 Quote Link to comment Share on other sites More sharing options...
rajivgonsalves Posted December 27, 2009 Share Posted December 27, 2009 most probably a javascript error check your javascript errors in IE Quote Link to comment Share on other sites More sharing options...
dflow Posted December 28, 2009 Author Share Posted December 28, 2009 most probably a javascript error check your javascript errors in IE ok it also doesnt work in ie8 :'( i get a unknown runtime error on these lines: Webpage error details User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; InfoPath.2; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729) Timestamp: Mon, 28 Dec 2009 09:37:07 UTC Message: Unknown runtime error Line: 340 Char: 7 Code: 0 URI: new-product-full-page-citycountry.php?CityID=2 Message: Unknown runtime error Line: 340 Char: 7 Code: 0 URI: new-product-full-page-citycountry.php?CityID=2 Message: Unknown runtime error Line: 340 Char: 7 Code: 0 URI: new-product-full-page-citycountry.php?CityID=2 line 340: // only if "OK" if (req.status == 200) { document.getElementById('statediv').innerHTML=req.responseText; } else { alert("There was a problem while using XMLHTTP:\n" + req.statusText); } Quote Link to comment Share on other sites More sharing options...
rajivgonsalves Posted December 28, 2009 Share Posted December 28, 2009 you should get ajax code that is cross browser compatible also IE8 has a developer console so you can pinpoint the problem Quote Link to comment Share on other sites More sharing options...
dflow Posted December 28, 2009 Author Share Posted December 28, 2009 apparently the original code works with both browsers 1e 6 and 8 here is the live demo http://roshanbh.com.np/dropdown/ i didnt make any changes to the javascript but rename the vars countryId to categoryId i ran the developer tool and it marked this line as problematic: document.getElementById('statediv').innerHTML=req.responseText; Quote Link to comment Share on other sites More sharing options...
rajivgonsalves Posted December 28, 2009 Share Posted December 28, 2009 I am not sure on this but I think your code should be, since there are 5 states in ajax and data is only available on readyState 4, because the others are initializing, sending, receiving etc. if (req.readyState == 4) { if (req.status == 200) { document.getElementById('statediv').innerHTML=req.responseText; } else { alert("There was a problem while using XMLHTTP:\n" + req.statusText); } } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.