Solved

javascript and jquery not working on NFL Scoreboard

Posted on 2013-05-24
2
520 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
[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 35

Accepted Solution

by:
Robert Schutt earned 500 total points
ID: 39194874
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
ID: 39194939
Helped me out and well commented making the code easier to interpret.
0

Featured Post

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

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

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…
Originally, this post was published on Monitis Blog, you can check it here . Websites are getting bigger and more complicated by the day. Video, images and custom fonts are all great for showcasing your product or service. But the price to pay in…
In this Micro Tutorial viewers will learn how to create navigation buttons that change on rollover, using CSS (Continuation of the CSS Image Sprite tutorial) Create a parent ID for all the list items       - Specify position: absolute and display: block…
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…

730 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