Solved

javascript and jquery not working on NFL Scoreboard

Posted on 2013-05-24
2
515 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
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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Use these top 10 tips to master the art of email signature design. Create an email signature design that will easily wow recipients, promote your brand and highlight your professionalism.
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
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 …
The viewer will learn how to dynamically set the form action using jQuery.

803 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