Solved

Loading Images from xml file

Posted on 2013-06-17
4
348 Views
Last Modified: 2013-06-18
I have a baseball field and I need to load each team players uniform. I wrote code for it and checked it in Fire Bug but Fire bug didn't display any messages.

here is the part that loads player uniforms on the field Attached is a Zip file that contains all necessary files and is hardcoded to work without any tweaking

var d = $(data);
 				var Team = $(d.find('TeamID'));
				var d = $(data);
                var Fielder = $(d.find('Fielders'));
                if (Fielder.attr('TeamID') == Team) {
                    $('#P').attr('src', 'http://images.sportsnetwork.com/MLB/attheballpark/pbp_logos/'+Team.attr('Uniform')+'.gif');
					 $('#C').attr('src', 'http://images.sportsnetwork.com/MLB/attheballpark/pbp_logos/'+Team.attr('Uniform')+'.gif');
					 
                    $('#FB').attr('src', 'http://images.sportsnetwork.com/MLB/attheballpark/pbp_logos/'+Team.attr('Uniform')+'.gif');
					 $('#SB').attr('src', 'http://images.sportsnetwork.com/MLB/attheballpark/pbp_logos/'+Team.attr('Uniform')+'.gif'); 
			 $('#SS').attr('src', 'http://images.sportsnetwork.com/MLB/attheballpark/pbp_logos/'+Team.attr('Uniform')+'.gif');
					 $('#TB').attr('src', 'http://images.sportsnetwork.com/MLB/attheballpark/pbp_logos/'+Team.attr('Uniform')+'.gif');
					 
                    $('#LF').attr('src', 'http://images.sportsnetwork.com/MLB/attheballpark/pbp_logos/'+Team.attr('Uniform')+'.gif');
					 $('#CF').attr('src', 'http://images.sportsnetwork.com/MLB/attheballpark/pbp_logos/'+Team.attr('Uniform')+'.gif'); 		 
				$('#RF').attr('src', 'http://images.sportsnetwork.com/MLB/attheballpark/pbp_logos/'+Team.attr('Uniform')+'.gif'); 		 
					 
					

Open in new window

New.zip
0
Comment
Question by:powerztom
[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
  • 2
4 Comments
 

Author Comment

by:powerztom
ID: 39254371
To clear things up the uniforms represent players in the baseball field Each Team has different uniforms so I want to load uniforms(players) and then load the other teams uniforms at the end of middle inning and then end of inning. the zip has everything.
Thanks for your help
0
 
LVL 35

Accepted Solution

by:
Robert Schutt earned 500 total points
ID: 39254394
I played around with this a bit and came up with the code below. You can take it out of the for loop by the way.
			var d = $(data);
			var Fielder = $(d.find('Fielders').find('Player:first'));
			var Team = $(d.find("Team[ID='" + Fielder.attr('TeamID') + "']"));
			var unfrm = Team.attr('Uniform'); // +'.gif';
			$('#P,#C,#FB,#SB,#SS,#TB,#LF,#CF,#RF').attr('src', 'http://images.sportsnetwork.com/MLB/attheballpark/pbp_logos/'+unfrm);

Open in new window

0
 
LVL 35

Expert Comment

by:Robert Schutt
ID: 39254713
Some more explanation:

* your code was looking for a node TeamID in the xml which doesn't exist.
* the Fielders node does not have any attributes, so I look at the first Player node inside it.
* the if condition was comparing 2 things that would never be the same (empty array and null) but also didn't error.
* the Uniform attribute already contains the .gif extension.
* the last line combines setting all src attributes in one selector because it's all the same image.
0
 

Author Closing Comment

by:powerztom
ID: 39256246
Thanks again this one I was clueless on. But you got it done. Kudos
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

Suggested Solutions

Title # Comments Views Activity
How do I split a variable to newline 2 41
isNaN issue on the Table input text 2 38
Bootstrap NavBar Not Working 2 27
display data from multiple ajax calls 9 36
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 …
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…

738 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