Forum Moderators: open
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
here is the code
Code:
function ReqCity() {
loader("citystatus"," Loading Cities... ");
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"," Loading Counties... ");
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.