?
Solved

Dropdown list is filling with too many values

Posted on 2010-11-17
2
Medium Priority
?
343 Views
Last Modified: 2012-05-10
I have developed a function called getSizes() that should grab all sizes based on the site and type of ad selected.  Meaning, there will be a certain amount of sizes per type of ad per site.  My issue is, each site has the same type of ad, therefore I'm getting sizes from each site based on that one type selected.  Man, I hope that makes sense.  Anyway, below is the code.
JS

function getSizes() {
	var site = document.getElementById("specSite").value;
	var type = document.getElementById("mediaType").value;
	var xSite = xmlDoc.getElementsByTagName("site");
	var xType = xmlDoc.getElementsByTagName("type");
	var xSize = xmlDoc.getElementsByTagName("adsize");
	for(var s=0; s<xSite.length; s++) {
		if(site == xSite[s].attributes.getNamedItem("name").value) {
			for(var t=0; t<xType.length; t++) {
				if(type == xType[t].attributes.getNamedItem("name").value) {
					for(var si=0; si<xSize.length; si++) {
						document.getElementById("iSize").innerHTML += "<option value=" + xSize[si].attributes.getNamedItem("size").value + ">" + xSize[si].attributes.getNamedItem("size").value + "</option>";
					}
				}
				break;
			}
		}
		break;
	}
}


XML

<sites>
	<site name="SITE">
		<adtypes>
			<type name="Image">
				<adsize size="300x250">
					<initial>40</initial>
					<polite>80</polite>
					<duration>15</duration>
					<fps>24</fps>
					<filetype>gif</filetype>
					<filetype>jpeg</filetype>
					<filetype>png</filetype>
				</adsize>
				<adsize size="336x280">
					<initial>40</initial>
					<polite>80</polite>
					<duration>15</duration>
					<fps>24</fps>
					<filetype>gif</filetype>
					<filetype>jpeg</filetype>
					<filetype>png</filetype>
				</adsize>
				<adsize size="300x600">
					<initial>40</initial>
					<polite>100</polite>
					<duration>15</duration>
					<fps>24</fps>
					<filetype>gif</filetype>
					<filetype>jpeg</filetype>
					<filetype>png</filetype>
				</adsize>

Hopefully you get the idea because there 2654 lines of code.

Open in new window

0
Comment
Question by:pingeyeg
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 16

Accepted Solution

by:
jmatix earned 2000 total points
ID: 34159356
You need to take types from the matching site only, right? Try changing your script as follows:
function getSizes() {
	var site = document.getElementById("specSite").value;
	var type = document.getElementById("mediaType").value;
	var xSite = xmlDoc.getElementsByTagName("site");
	for(var s=0; s<xSite.length; s++) {
		if(site == xSite[s].attributes.getNamedItem("name").value) {
			var xType = xSite[s].getElementsByTagName("type");
			for(var t=0; t<xType.length; t++) {
				if(type == xType[t].attributes.getNamedItem("name").value) {
					var xSize = xType[t].getElementsByTagName("adsize");
					for(var si=0; si<xSize.length; si++) {
						document.getElementById("iSize").innerHTML += "<option value=" + xSize[si].attributes.getNamedItem("size").value + ">" + xSize[si].attributes.getNamedItem("size").value + "</option>";
					}
				}
				break;
			}
		}
		break;
	}
}

Open in new window

0
 
LVL 1

Author Comment

by:pingeyeg
ID: 34167445
Sweet... so, in essence, one of the lines would read:

var xType = xmlDoc.getElementsByTagName("site").getElementsByTagName("type").value;

I didn't know you could do that.

I keep on learning.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question