Solved

Dropdown list is filling with too many values

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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…

696 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