Hello,

I am trying to populate data from an xml file when a certain catergory from the dropdown menu is selected.

The dropdown menu is also populated from a xml source different from the one where the data is stored that needs to be pulled.

so when a category is selected from the dropdown - the selected value will populate the data from the xml source.

I am having trouble displaying the data when a category is selected from the drop down menu.

here is the code:

<html>
<head>
<title>AJAX</title>
<link href="layout.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="zxml.js"></script>
<script type="text/javascript">

   	
function getProduct() {
	var oXmlHttp = zXmlHttp.createRequest();
	oXmlHttp.open("post","products.xml",true);
	oXmlHttp.onreadystatechange = function () {
		if (oXmlHttp.readyState == 4) {
			if (oXmlHttp.status == 200) {
			
				var product = response.getElementsByTagName('product_line').SelectedIndex;

				// not sure where to go from here????
				
				}
				}
	
}
}


function popList() {
	var oXmlHttp = zXmlHttp.createRequest();
	oXmlHttp.open("get","categories.xml",true);
	oXmlHttp.onreadystatechange = function () {
		if (oXmlHttp.readyState == 4) {
			if (oXmlHttp.status == 200) {
			
			
				var response = oXmlHttp.responseXML;
				var theIndex = 0;
				var manList = document.getElementById("products");
			
			
				var o = new Option("Please Select a Category2","what ever");
				manList.options.add(o,theIndex);
				
				
				var my_names = response.getElementsByTagName('category');
				for(var i=0; i<my_names.length; i++)
				{
					
					++theIndex;
					var theName = response.getElementsByTagName('category')[i].firstChild.data;
					var productLine = response.getElementsByTagName('category')[i].getAttribute('product_line')
				
				
					var optionText = productLine + " - " + theName;
					var optionValue = productLine + "|" + theName;
					
					var o = new Option(optionText,optionValue);
					manList.options.add(o,theIndex);
					var Timer = setInterval(theName,productLine);
					
				}		
				
			} else {
				displayCustomerInfo("An error occurred: " + oXmlHttp.statusText); //statusText is not always accurate
			}
			
		}   
	}
	oXmlHttp.send(null);	
}
</script>



</head>
<body onLoad="popList()">
Ajax Test Page<br />
<form>
<select id="products">
</select>

<input type="button" value="Show Products" onClick="getProduct()">  
</form>
<div id="body">to be replaced</div>
</body>
</html>

and here is the xml source I would like to pull once a category is selected... the category will be the "sub_group" attribute from this code

<?xml version="1.0" encoding="iso-8859-1"?>
<data>
	<product product_line="Media &amp; USB Keys" sub_group="CD" sku="100CDQ80LS3">
		<brand>Sony</brand>
		<heading>Sony CD-R</heading>
		<description>Designed for optimum performance with multi-speed drives. Compatible with selected CDR-RW drives. 1x--48x write speed. 80 minutes recording time; 700 MB capacity.</description>
		<descriptor>100-pack spindle</descriptor>
		<image>images/trans.gif</image>
	</product>
	<product product_line="Media &amp; USB Keys" sub_group="CD" sku="10CDQ80">
		<brand>Sony</brand>
		<heading>Sony CD-R</heading>
		<description>Designed for optimum performance with multi-speed drives. Compatible with selected CDR-RW drives. 1x--48x write speed. 80 minutes recording time; 700 MB capacity.</description>
		<descriptor>10-pack with slim jewel cases</descriptor>
		<image>images/trans.gif</image>
	</product>
	<product product_line="Media &amp; USB Keys" sub_group="CD" sku="CDQ80SB" >
		<description>Designed for optimum performance with multi-speed drives. Compatible with selected CDR-RW drives. 1x--48x write speed. 80 minutes recording time; 700 MB capacity.</description>
		<descriptor>50-pack spindle</descriptor>
		<image>images/trans.gif</image>
		<brand>Sony</brand>
		<heading>Sony CD-R</heading>
	</product>
	
	
	
	<product product_line="Media &amp; USB Keys" sub_group="Midrange Media" sku="1838000">
		<brand>Maxell</brand>
		<heading>Maxell LTO Data Cartridge</heading>
		<description>4.7 GB oOptimized for high capacity and performance with exceptional reliability in either a stand-alone or automated environment. Patented ceramic coated metal particle tape. Ideal for server back-up, restore and archival applications.</description>
		<descriptor>Ultrium 1. 100/200 GB</descriptor>
		<image>images/trans.gif</image>
	</product>
	<product product_line="Media &amp; USB Keys" sub_group="Midrange Media" sku="1838500">
		<brand>Maxell</brand>
		<heading>Maxell LTO Data Cartridge</heading>
		<description>4.7 GB oOptimized for high capacity and performance with exceptional reliability in either a stand-alone or automated environment. Patented ceramic coated metal particle tape. Ideal for server back-up, restore and archival applications.</description>
		<descriptor>Ultrium 2. 200/400 GB</descriptor>
		<image>images/trans.gif</image>
	</product>
	<product product_line="Media &amp; USB Keys" sub_group="Midrange Media" sku="1839000">
		<brand>Maxell</brand>
		<heading>Maxell LTO Data Cartridge</heading>
		<description>4.7 GB oOptimized for high capacity and performance with exceptional reliability in either a stand-alone or automated environment. Patented ceramic coated metal particle tape. Ideal for server back-up, restore and archival applications.</description>
		<descriptor>Ultrium 3. 400/800 GB</descriptor>
		<image>images/trans.gif</image>
	</product>
	<product product_line="Media &amp; USB Keys" sub_group="Midrange Media" sku="183906-0">
		<brand>Maxell</brand>
		<heading>Maxell LTO Data Cartridge</heading>
		<description>4.7 GB oOptimized for high capacity and performance with exceptional reliability in either a stand-alone or automated environment. Patented ceramic coated metal particle tape. Ideal for server back-up, restore and archival applications.</description>
		<descriptor>Ultrium 4. 800 GB/1.6 TB</descriptor>
		<image>images/trans.gif</image>
	</product>
	
	
	<product product_line="Media &amp; USB Keys" sub_group="DVD" sku="639011">
		<brand>Maxell</brand>
		<heading>Maxell DVD+R</heading>
		<description>4.7 GB of storage capacity or 120 minutes. Up to 16x write speed. Write-once and single-sided.</description>
		<descriptor>25-pack spindle indle</descriptor>
		<image>images/trans.gif</image>
	</product>
	<product product_line="Media &amp; USB Keys" sub_group="DVD" sku="639013">
		<brand>Maxell</brand>
		<heading>Maxell DVD+R</heading>
		<description>4.7 GB of storage capacity or 120 minutes. Up to 16x write speed. Write-once and single-sided.</description>
		<descriptor>50-pack spindle</descriptor>
		<image>images/trans.gif</image>
	</product>
	<product product_line="Media &amp; USB Keys" sub_group="DVD" sku="639016">
		<brand>Maxell</brand>
		<heading>Maxell DVD+R</heading>
		<description>4.7 GB of storage capacity or 120 minutes. Up to 16x write speed. Write-once and single-sided.</description>
		<descriptor>100-pack spindle </descriptor>
		<image>images/trans.gif</image>
	</product>

	
	
	
	
	<product product_line="Media &amp; USB Keys" sub_group="CD" sku="648200">
		<brand>Maxell</brand>
		<heading>Maxell 48x CD-Recordable</heading>
		<description>48x write speed. 80 minutes recording time; 700 MB capacity.</description>
		<descriptor>100-pack spindle</descriptor>
		<image>images/648200.jpg</image>
	</product>
	<product product_line="Media &amp; USB Keys" sub_group="CD" sku="648210">
		<brand>Maxell</brand>
		<heading>Maxell 48x CD-Recordable</heading>
		<description>48x write speed. 80 minutes recording time; 700 MB capacity.</description>
		<descriptor>Slim jewel case. Package of 10</descriptor>
		<image>images/648210.jpg</image>
	</product>
	<product product_line="Media &amp; USB Keys" sub_group="CD" sku="648250">
		<brand>Maxell</brand>
		<heading>Maxell 48x CD-Recordable</heading>
		<description>48x write speed. 80 minutes recording time; 700 MB capacity.</description>
		<descriptor>50-pack spindle</descriptor>
		<image>images/648250.jpg</image>
	</product>
	
	<product product_line="Media &amp; USB Keys" sub_group="Blu Ray" sku="631002">
		<brand>Maxell</brand>
		<heading>Maxell Blu-ray DVD </heading>
		<description>Single-layer disc. 1--2x. 25 GB.  </description>
		<descriptor>Rewritable</descriptor>
		<image>images/trans.gif</image>
	</product>
	
	
</data>

I know this isn't the answer to your question but you could try using a JS library like jQuery. It makes ajax handling and XML manipulation a breeze. Will try to recreate your problem to help with a solution.

okay.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.