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 - 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)">

Link to comment
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);
				}

 

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.