Jump to content

onChange not working in ie6


dflow

Recommended Posts

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 - [email protected]
// 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)">

Link to comment
https://forums.phpfreaks.com/topic/186441-onchange-not-working-in-ie6/
Share on other sites

most probably a javascript error check your javascript errors in IE

 

ok it also doesnt work in ie8  :confused: :'( :wtf:

 

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

 

 

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;

 

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.