Solved

Duplicate score on NFL SCOREBOARD JQUERY XML HELP

Posted on 2013-06-06
3
562 Views
Last Modified: 2013-06-06
I have a Nfl Scoreboard and I have it run through a complete set of xml game files. The problem is the same score comes up for visitor and hometeam. But i use a if statement

like this if ($(Team).attr('vh') == "A") {
and then
if ($(Team).attr('vh') == "H") {

Just hardcode attached xml file

 function loadData() {
    $.ajax({
      type: "GET",
      url:  xmlPath+"/"+xmlGameID+'_'+counterXml+".xml",
      dataType: "xml",
      success: function(data){
        var d = $(data);
        d.find('Team').each(function(i,Team){
          if ($(Team).attr('vh') == "A") {
            $('#imgVisitHelmet').attr('src', 'http://images.sportsnetwork.com/nfl/atthegridiron/end_zone/'+$(Team).attr('ID')+"_helmet_away.png");
		  }
          if ($(Team).attr('vh') == "A") {
		  var VS1 = $(d.find('Team')).find('Linescore');
		  var vs2 = VS1.attr('Score');
		  $('#VS').html(vs2);}
          if ($(Team).attr('vh') == "H") {
            $('#imgHomeHelmet').attr('src', 'http://images.sportsnetwork.com/nfl/atthegridiron/end_zone/'+$(Team).attr('ID')+"_helmet_home.png");
         }
		 if ($(Team).attr('vh') == "H") {
		   var HS1 = $(d.find('Team')).find('Linescore');
		  var hs2 = HS1.attr('Score');
		  $('#HS').html(hs2); 
		 }
        });
        var Play = $(d.find('Play'));
        // changed all below to just use the variables that contain the text directly, as the arrays do not exist and don't seem necessary in this situation
		
		var RD = Play.attr('ResultingDown') ;
        $('#VRd').html(RD);
		var Rtg = Play.attr('ResultingToGo') ;
        $('#VRtg').html(Rtg);
        var inn = Play.attr('TimeLeft') ;
        $('#Time').html(inn ); // timeleft[inn]
        var bo = Play.attr('BallYrd') ;
        $('#Ballon').html(bo ); // ballyrd[bo]
        var dn = Play.attr('ResultingDown') ;
        $('#Down').html(dn ); // resultingdown[dn]
        var ydtogo = Play.attr('ResultingToGo') ;
        $('#Ydstogo').html(ydtogo ); // resultingtogo[ydtogo]
        var qtr = Play.attr('Quarter') ;
        $('#Q').html(qtr ); // quarter[qtr]
        ++counterXml;
      }
    });
  }
</script>

Open in new window

Top.html
AB-3171-120.xml
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
3 Comments
 
LVL 35

Accepted Solution

by:
Robert Schutt earned 500 total points
ID: 39226992
On line 8 a loop is started which is executed twice because there are always 2 <Team> nodes in the xml files. In the existing code, inside the loop, $(Team) is used to refer to each respective node for which the loop is being executed.

In the new code, on lines 13 and 20, you repeat the code $(d.find('Team')), which does a new find() on the original data and will refer to the first <Team> node each time. So that should be replaced by $(Team) like this:
var VS1 = $(Team).find('Linescore');

Open in new window

and
var HS1 = $(Team).find('Linescore');

Open in new window

0
 

Author Closing Comment

by:powerztom
ID: 39227051
Thanks Rob for explanation I learning slowly but surely. Your the Best EE Guy seriously
0
 
LVL 35

Expert Comment

by:Robert Schutt
ID: 39227081
You're welcome and thanks for your kind words, I'm getting a double ego boost today.
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

Suggested Solutions

Title # Comments Views Activity
XML error not understood 5 32
Problem in javascript 17 59
Horizontal Full Calendar using php 5 43
Time Picker 3 22
PROBLEM: The other day I was working on adding an ajax request to a webpage that already had a dialog box on the page.  The dialog box was using relative positioning to be positioned next to a form field I had on the page.  Everything was working…
Many times as a report developer I've been asked to display normalized data such as three rows with values Jack, Joe, and Bob as a single comma-separated string such as 'Jack, Joe, Bob', and vice versa.  Here's how to do it. 
The viewer will learn how to dynamically set the form action using jQuery.
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)
Suggested Courses

751 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