I want my code yo retreive an xml file and display it as an options list under a select object but the code in google chrome is giving this error "Uncaught TypeError: Cannot read property '0' of undefined" and i dont know what to do about it please can someone help me.
<script type="text/ecmascript">
var oreofe;
var xmlHttpDoc = new XMLHttpRequest();
function loadWing()
{
var build = document.getElementsByName('building').item().value;
alert(build);
if(xmlHttpDoc)
{
xmlHttpDoc.open("GET", "test.php?ret=build", true);
xmlHttpDoc.onreadystatechange = function()
{
if(xmlHttpDoc.readyState==4 && xmlHttpDoc.status==200)
{
var xmlDocument;
xmlDocument = xmlHttpDoc.responseXML;
oreofe = xmlDocument.getElementsByTagName('option');
listOptions();
}
}
xmlHttpDoc.send(null);
}
}
function listOptions()
{
var loopIndex;
for (loopIndex = 0; loopIndex < oreofe.length; loopIndex++ )
{
document.getElementsByName('wing').options[loopIndex].v = new Option(oreofe[loopIndex].firstChild.data);
}
}
</script>
this is the html part
<p><label>Problem Location Building</label></p>
<p><select name="building" onchange="loadWing()"><option value="daniel">Daniel Hall</option><option value="john">John Hall</option><option value="esther">Esther Hall</option><option value="deborah">Deborah Hall</option></select></p>
<p><label>Problem Location Wing</label></p>
<p><select name="wing" ><option>Select a scheme</option></select></p>