Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

xml to select options help 1

Status
Not open for further replies.

warmdownhere

Programmer
Aug 23, 2008
5
0
0
US
I'm trying to convert a string to xml and then fill a select box with that info. Not working Thoughts?

var test = "<NewDataSet<Table><GenreID>d0e583d7-393d-47b1-8f47-e1b814e6d7c6</GenreID><Name>Politics</Name></Table><Table><GenreID>37f4a8ad-98d8-4b2c-9c30-4e2ff00dee2a</GenreID><Name>Shopping</Name></Table></NewDataSet>";

var xmlobject = (new DOMParser()).parseFromString(test, "text/xml");
// get a reference to the root-element "NewDataSet"
var root = xmlobject.getElementsByTagName('NewDataSet')[0];
// get reference to "table" element

var Tables = root[0].getElementsByTagName("Table");
// in the "table" we have a GenreID, so get that
var genreID = Tables[0].getElementsByTagName("GenreID");
var name = Tables[0].getElementsByTagName("Name");

for (i=0;i<=genreID.length;i++)
{
document.forms['genreform'].genre.options[0] = new Option(name,genreID);
}

Thanks,

Ted
 
good catch, I had chopped the xml so that it didn't take up the whole post. DOMParser is for Mozilla - also pointed me in a good direction. I'm creating a Vista Gadget and dont think that would work. Here is where I'm at, its better... I'm now filling the options, but they are showing up as '[object]' i have tried nodeValue, toString... Thoughts?

var test = "<NewDataSet><Table><GenreID>37f4a8ad-98d8-4b2c-9c30-4e2ff00dee2a</GenreID><Name>Shopping</Name></Table></NewDataSet>";
var genrename;
xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async="false";
xmlDoc.loadXML(test);

genrename = xmlDoc.getElementsByTagName("Name");
for (var i=0; i<genrename.length; i++)
{
document.forms['genreform'].genre.options = new Option(genrename ,genrename);
}
 
> document.forms['genreform'].genre.options[ignore][/ignore] = new Option(genrename ,genrename);
[tt] document.forms['genreform'].genre.options = new Option(genrename[red].text[/red] ,genrename[red].text[/red]);[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top