|
Summary
You need to have IE version > 4.0. You should have knowledge of how to create Data island in IE.
I am going to show here a generic method in Javascripting through which you can fill any select HTML elements in your page. In fact in one of my application I have 4 Select Drop down box and they all get filled up (as page loads) by calling this method.
function Fillselectbox(elemindex, nodenme) //for elemindex,nodenme see below in additional information
{
var strText;
var theXMLDoc = new ActiveXObject(Msxml2.DOMDocument); //Create the MS XML DOM OBJECT
var nodedata;
theXMLDoc.async = false;
if (document.readyState == complete)
{
theXMLDoc = HeOpt; // load the Data Island file
nodedata = theXMLDoc.selectNodes(nodenme)
document.all(elemindex).options.length = nodedata.length;
//This if I coded because of my application requirement. You may or may not need it depends on your
//requirement
if (nodedata.length > 1)
{
document.all(elemindex).options.length = nodedata.length+1;
document.all(elemindex).options[0].value= ALL;
document.all(elemindex).options[0].text = ALL;
}
//This for loop fills the select box
for (var i=0; i < nodedata.length; i++)
{
strText = nodedata.item(i).text
if (nodedata.length > 1)
{
document.all(elemindex).options[i+1].value= strText; //I am giving value to each entry same as text. You may
//choose to give it separate value by having one of node as value or attribute of node which you are picking for text.
document.all(elemindex).options[i+1].text = strText;
}
else
{
document.all(elemindex).options[i].value= strText;
document.all(elemindex).options[i].text = strText;
}
strTextSave = strText;
}
}
}
| Further additional information | |
Updating comments...
Updating comments...
|