XMLHttpRequest and IE 8 error - in jsp/servlet applicaton
- by Greener
Hello,
I am using HMLHttpRequest object to retrieve information from the database via servlet and populate combo box.
The code run in Firefox 3.6 and Chrome without any problems.
However, I have a problem with IE 8.
here is my code:
var req;
var isIE;
function initRequest(){
if (window.XMLHttpRequest) {
req = new XMLHttpRequest();
} else if (window.ActiveXObject) {
isIE = true;
req = new ActiveXObject("Microsoft.XMLHTTP");
}
}
function populateMuniBox(countyCode)
{
initRequest();
req.onreadystatechange = populateMuniCallback;
req.open("GET","./CntyMuni?county="+ countyCode,true);
req.send(null);
}
function populateMuniCallback()
{
//clean combo box
document.getElementById("cmbMuni").options.length = 0;
var muni;
if(req.readyState==4){
if (req.status == 200){
var XMLresult = req.responseXML;
var muni = XMLresult.getElementsByTagName("rec");
}
}
for(var i=0;i<muni.length;i++)
{
//create Html option Element
var opt = document.createElement("option");
//Set up the option - add values from XML
opt.value = muni[i].getAttribute("code");
opt.text = muni[i].getAttribute("desc");
//add the option to the combobox
document.getElementById("cmbMuni").appendChild(opt);
}
}
HMTL code
//First combo box the sends a value to the script
<td> <select name="cn" id="county" onchange="populateMuniBox(this.value)">
// Second cmb
<select name="mu" id="cmbMuni" ></select>
IE error: 'lenght' is null or not an object cntymuni.jsp Code: 0
I am not sure how to fix the error.