Solved

javascript and jquery not working on NFL Scoreboard

Posted on 2013-05-24
2
505 Views
Last Modified: 2013-05-24
Hey,

I am working on a Football Gamecast I used code from a previous project and for whatever reason it is not coming up Please Check out.Attached are necessary files

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>The Sports Network</title>
<style type="text/css">
.formatcell {
	text-align: center;
	vertical-align: top;
}
.formatcelldown {
	text-align: center;
	vertical-align: bottom;
}
.formatcellcenter {
	text-align: center;
	vertical-align: middle;
}
</style>
</head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
 var xmlPath = '/xml/nfl/scores/real';
  var xmlGameID = 'AB-3171_'+counterXml+".xml";
  var Ballon = "", Down = "", Ydstogo = "", Q = "", Time = "";
  var counterXml = 0;
   function loadData() {
  $.ajax({
    type: "GET",
    url: xmlGameID, //xmlPath+"/"+xmlGameID+".xml",
    dataType: "xml",
    success: function(data){
      var d = $(data);
	 var Team = $(d.find('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') = "H") {
                    $('#imgHomeHelmet').attr('src', 
    'http://images.sportsnetwork.com/nfl/atthegridiron/end_zone/'+Team.attr('ID')
	 +"_helmet_home.png");
	  var Play = $(d.find('Play'));
	 var inn = Play.attr('TimeLeft') ;
        $('#Time').html(timeleft[inn] );
		 var bo = Play.attr('BallYrd') ;
        $('#Ballon').html(ballyrd[bo] );
		 var dn = Play.attr('ResultingDown') ;
        $('#Down').html(resultingdown[dn] );
		var ydtogo = Play.attr('ResultingToGo') ;
        $('#Ydstogo').html(resultingtogo[ydtogo] );
		var qtr = Play.attr('Quarter') ;
        $('#Q').html(quarter[qtr] );
			    }
				}
	  ++counterXml;
	}
	  });
   }
</script>
<body>
<table width="800" border="1">
  <tr>
    <td height="21" colspan="3" class="formatcell" id="Visitor">Visitor</td>
    <td colspan="4" class="formatcell" id="Time">TimeRemaining</td>
    <td colspan="3" class="formatcell" id="Hometeam">Hometeam</td>
  </tr>
  <tr>
    <td width="76" height="64"><p align="center" class="formatcell"><img src="VistorHelmet.png" name="imgVisitHelmet" width="63" height="62" id="imgVisitHelmet"></p></td>
    <td width="76" id="VTeamname">Teamname</td>
    <td width="82" id="VistorScore">VistorScore</td>
    <td width="58" class="formatcellcenter">Ball on</td>
    <td width="57" class="formatcellcenter">Down</td>
    <td width="73" class="formatcellcenter">Yds to go</td>
    <td width="69" class="formatcellcenter">Quarter</td>
    <td width="84" class="formatcellcenter" id="HomeScore">HomeScore</td>
    <td width="91" class="formatcellcenter" id="HTeamName">TeamName</td>
    <td width="92" class="formatcell"><img src="HomeHelmet.png" name="imgHomeHelmet" width="66" height="61" id="imgHomeHelmet"></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td class="formatcell" id="VDownYard">DownYard</td>
    <td>&nbsp;</td>
    <td class="formatcell" id="Ballon">Ballon</td>
    <td class="formatcell" id="Down">Down</td>
    <td class="formatcell" id="Ydstogo">Ydstogo</td>
    <td class="formatcell" id="Q">Q</td>
    <td class="formatcell">&nbsp;</td>
    <td class="formatcell" id="HDownYard">DownYard</td>
    <td class="formatcell">&nbsp;</td>
  </tr>
</table>
<p id="demo">
<script>
var myVar=setInterval(function(){myTimer()},5000);

function myTimer()
{

var d=new Date();
var t=d.toLocaleTimeString();
document.getElementById("demo").innerHTML=t;
loadData();
//checkStatus();
}
        </script>
</body>
</html>

Open in new window

Top.html
AB-3171-0.xml
AB-3171-1.xml
AB-3171-2.xml
AB-3171-3.xml
AB-3171-4.xml
AB-3171-5.xml
HomeHelmet.png
VistorHelmet.png
0
Comment
Question by:powerztom
2 Comments
 
LVL 35

Accepted Solution

by:
Robert Schutt earned 500 total points
Comment Utility
Try this, I tried to comment elaborately the most important changes I made:
  var xmlPath = '/xml/nfl/scores/real';
  var xmlGameID = 'AB-3171'; // game id only, _counter.xml will be added in the ajax call
  var Ballon = "", Down = "", Ydstogo = "", Q = "", Time = ""; // unused?
  var counterXml = 0;
  function loadData() {
    $.ajax({
      type: "GET",
      url: xmlPath+"/"+xmlGameID+'_'+counterXml+".xml",
      dataType: "xml",
      success: function(data){
        var d = $(data);
        //var Team = $(d.find('Team')); // replaced with loop
        d.find('Team').each(function(i,Team){
          if ($(Team).attr('vh') == "A") { // use DOUBLE equals sign for comparison expression!
            $('#imgVisitHelmet').attr('src', 'http://images.sportsnetwork.com/nfl/atthegridiron/end_zone/'+$(Team).attr('ID')+"_helmet_away.png");
          }
          if ($(Team).attr('vh') == "H") {
            $('#imgHomeHelmet').attr('src', 'http://images.sportsnetwork.com/nfl/atthegridiron/end_zone/'+$(Team).attr('ID')+"_helmet_home.png");
          }
        });
        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 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;
      }
    });
  }

Open in new window

0
 

Author Closing Comment

by:powerztom
Comment Utility
Helped me out and well commented making the code easier to interpret.
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
This article describes how to create custom column layout styles for Bootstrap. The article uses 5 columns to illustrate the concept, but the principle can be extended to any number of columns.
In this tutorial viewers will learn how to position overlapping items using z-index in CSS. They will also learn the restrictions on the z-index property.  Create a new HTML document with an internal stylesheet.: Create a div in CSS and name it Red.…
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …

762 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

6 Experts available now in Live!

Get 1:1 Help Now