Solved

Dropdown list is filling with too many values

Posted on 2010-11-17
2
341 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 500 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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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…

688 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