?
Solved

javascript and jquery not working on NFL Scoreboard

Posted on 2013-05-24
2
Medium Priority
?
530 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 2000 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Building a website can seem like a daunting task to the uninitiated but it really only requires knowledge of two basic languages: HTML and CSS.
In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
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…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…
Suggested Courses

770 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