Please help take a look at the following code, its working when calling function displayResult() with button onclick. but I want it to be automatically run when open the page....I've tried but still not working....Thanks
<form>
<select id="mySelect">
<option>SELECT</option>
</select>
</form>
<script language="JavaScript" type="text/javascript">
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.open("GET","xmltag.xml",false);
xmlhttp.send();
xmlDoc=xmlhttp.responseXML;
x2=xmlDoc.getElementsByTagName("CONTROL_POINT");
function displayResult()
{
for (i=0;i<x2.length;i++)
{
var x=document.getElementById("mySelect");
var option=document.createElement("option");
option.text=x2[i].childNodes[0].nodeValue;
try
{
// for IE earlier than version 8
x.add(option,x.options[null]);
}
catch (e)
{
x.add(option,null);
}
}
}
</script>
var opt = new Option(text, value)which works in every browser back to the beginning. Then just append it it to the select:x.options[x.options.length] = opt;or similar.