Farayic
Programmer
- Sep 25, 2008
- 2
I am trying to fill a select box with xml values. There is nothing filling in. Please help:
Here is my code and xml file:
HTML FILE:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "
<!-- XML in easy steps - Page 164. -->
<html xmlns="
<head>
<title>Get All Data</title>
<!-- XML in easy steps - p.164-165 -->
<meta http-equiv = "Content-Type" content = "text/html;charset=UTF-8" />
<script type="text/javascript">
/* <![CDATA[ */
var xmlDoc;
function loadXmlDoc()
{
try
{
if (window.ActiveXObject)
{
xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async=false;
xmlDoc.load("music.xml");
LoadOptions;
}
else if (document.implementation && document.implementation.createDocument)
{
xmlDoc = document.implementation.createDocument("","",null);
xmlDoc.load("music.xml");
xmlDoc.onload=LoadOptions;
}
}
catch(err)
{
document.getElementById("box").innerHTML = "XML data is unavailable";
}
}
var genrename;
function LoadOptions()
{
genrename = xmlDoc.getElementsByTagName("Name");
for (var i=0; i<genrename.length; i++)
{
document.forms['genreform'].genre.options = new Option(genrename.text ,genrename.text);
}
}
window.onload=loadXmlDoc;
//window.onload=loadOptions;
/* ]]> */
</script>
</head>
<body>
<form name="genreform">
<select name="genre" >
<option value="Test"> Testing</Option>
</select>
</form>
<div id = "box" style= "background:yellow;width:320px;padding:5px"> </div>
</body>
</html>
XML FILE:
<?xml version="1.0" encoding="ISO8859-1" ?>
<NewDataSet>
<CD>
<Name>Music</Name>
</CD>
<CD>
<Name>Politics</Name>
</CD>
<CD>
<Name>Shopping</Name>
</CD>
</NewDataSet>
Here is my code and xml file:
HTML FILE:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "
<!-- XML in easy steps - Page 164. -->
<html xmlns="
<head>
<title>Get All Data</title>
<!-- XML in easy steps - p.164-165 -->
<meta http-equiv = "Content-Type" content = "text/html;charset=UTF-8" />
<script type="text/javascript">
/* <![CDATA[ */
var xmlDoc;
function loadXmlDoc()
{
try
{
if (window.ActiveXObject)
{
xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async=false;
xmlDoc.load("music.xml");
LoadOptions;
}
else if (document.implementation && document.implementation.createDocument)
{
xmlDoc = document.implementation.createDocument("","",null);
xmlDoc.load("music.xml");
xmlDoc.onload=LoadOptions;
}
}
catch(err)
{
document.getElementById("box").innerHTML = "XML data is unavailable";
}
}
var genrename;
function LoadOptions()
{
genrename = xmlDoc.getElementsByTagName("Name");
for (var i=0; i<genrename.length; i++)
{
document.forms['genreform'].genre.options = new Option(genrename.text ,genrename.text);
}
}
window.onload=loadXmlDoc;
//window.onload=loadOptions;
/* ]]> */
</script>
</head>
<body>
<form name="genreform">
<select name="genre" >
<option value="Test"> Testing</Option>
</select>
</form>
<div id = "box" style= "background:yellow;width:320px;padding:5px"> </div>
</body>
</html>
XML FILE:
<?xml version="1.0" encoding="ISO8859-1" ?>
<NewDataSet>
<CD>
<Name>Music</Name>
</CD>
<CD>
<Name>Politics</Name>
</CD>
<CD>
<Name>Shopping</Name>
</CD>
</NewDataSet>