BizTalk Utilities CV ,   Jobs ,   Code library
 
Home Page


Add/Edit your code items
Search the code library
Browse for the code library


JavaScript
XML Basics Handbook


 
 

 LAMP >>


By Munish Kohli
First Posted 07/31/2003
Times viewed 611

Dynamically Filling HTML Select Box from XML Data Island using Javascript.


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;

 }

 }

}

Additional information

Further additional information


Rate this article on a scale of 1 to 10 (3 votes, average 6)

Your vote :  

 LAMP >>





Leave a comment for this article
Your name
Your email (optional)
Your comment
Optional: Upload an attachment
Enter the code shown:

 
 

    Email TopXML