Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

javascript and jquery not working on NFL Scoreboard

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

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

Question has a verified solution.

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

Finding original email is quite difficult due to their duplicates. From this article, you will come to know why multiple duplicates of same emails appear and how to delete duplicate emails from Outlook securely and instantly while vital emails remai…
A while back, I ran into a situation where I was trying to use the calculated columns feature in SharePoint 2013 to do some simple math using values in two lists. Between certain data types not being accessible, and also with trying to make a one to…
In this tutorial viewers will learn how to embed an audio file in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: : The declaration should display (CODE) HTML5 is supported by the most recent versions of all major browsers…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).
Suggested Courses

578 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