Solved

Dropdown list is filling with too many values

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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…

706 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now