Forum Moderators: open

Message Too Old, No Replies

IE gives ajax Error: Object Required

IE gives ajax Error: Object Required

         

phparion

5:17 am on Jul 27, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Hi

I am working with an ajax-php-mysql code. the code populates two dropdowns on the selection of one parent (3rd) dropdown. the code is working fine without any problem in FireFox but IE gives error.

below is the code in question

Code:

<script language="JavaScript" type="text/javascript">

function createRequestObject() {
var ro;
var browser = navigator.appName; //ERROR LINE
if(browser == "Microsoft Internet Explorer"){
ro = new ActiveXObject("Microsoft.XMLHTTP");
// alert("object for IE");
}else{
ro = new XMLHttpRequest();
//alert("object for Firefox");
}
return ro;
}

var http = createRequestObject();


the ERROR LINE gives (Error: Object Required) error in IE and script does not work. Can anybody guide me please what's wrong with this line that is giving error?

thank you very much

phparion

5:18 am on Jul 27, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



on further debugging i noticed that IE is not picking state dropdown name therefore giving error. first of all when i load the page i get error Object Required as explained in the previous post... after that when i select a state from state dropdown i get the STATE NAME from ALERT for both county and city dropdowns in FF but not in IE.

here is the code
Code:

function ReqCity() {

loader("citystatus","&nbsp; Loading Cities... &nbsp;");
document.getElementById('city').options.length = 0;
alert("i am sending request to server");
var state = document.getElementById('state').value;
alert(state + " is the state name");
//document.getElementById('citystatus').innerHTML = '';
http.open('get', 'suckcity.php?state='+state);
http.onreadystatechange = handleResponseCity;
http.send(null);
//alert("server request completed");
}

function handleResponseCity() {
//alert("checking call state");
if(http.readyState == 4){
// alert("response on state 4");
var response = http.responseText;
var update = new Array();

if(response.indexOf('¦'!= -1)) {
update = response.split('¦');
alert(update);
// alert("i received positive packets");
document.getElementById('citystatus').innerHTML = "";
var loopEnd = update.length;

for(i=0; i<loopEnd; i++) {
document.forms['add_listing'].city.options[i] = new Option(update[i]);
} // end for loop

//document.getElementById(update[0]).innerHTML = update[1];
//alert("i am sending request to DIV now");

}
}
}

function ReqCounty() {
loader("countystatus","&nbsp; Loading Counties... &nbsp;");
document.getElementById('county').options.length = 0;
alert("i am sending county request to server");
var state = document.getElementById('state').value;

alert(state + " is the state name for county");
//document.getElementById('citystatus').innerHTML = '';
http.open('get', 'suckcounty.php?state='+state);
http.onreadystatechange = handleResponseCounty;
http.send(null);
//alert("server request completed");
}

function handleResponseCounty() {
//alert("checking call state");
if(http.readyState == 4){
// alert("response on state 4");
var response = http.responseText;
var update = new Array();

if(response.indexOf('¦'!= -1)) {
update = response.split('¦');
alert('county reply'+update);
// alert("i received positive packets");
document.getElementById('countystatus').innerHTML = "";
var loopEnd = update.length;

for(i=0; i<loopEnd; i++) {
document.forms['add_listing'].county.options[i] = new Option(update[i]);
} // end for loop
ReqCity();
//document.getElementById(update[0]).innerHTML = update[1];
//alert("i am sending request to DIV now");

}
}
}


i am using both Name and ID attribute for the dropdown

Code:

<select id="state" name="state" onChange="ReqCounty();">

any help will be much appreciated.

phparion

9:00 am on Jul 30, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



i have solved the issue thanks