Solved

Unable to load functions from external Javascript file

Posted on 2014-01-07
4
1,006 Views
Last Modified: 2014-01-07
I have two functions which I want to call external. The two functions donot work however when I dump the functions into a single html doc is works. Is there something I'm missing. I swear I used to do this and it wasn't a problem. Ok First is html doc then external javascript file.

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>NHL Scoreboard</title>
<link rel="stylesheet" href="http://powerzsoftware.com/css/jquery-ui-1.8.9.customver1.css">
<style type="text/css">
.CENTERMID {	text-align: center;
	vertical-align: middle;
}
.WHITETEXT {
	font-family: "Times New Roman", Times, serif;
	font-size: 36px;
	font-weight: bold;
	color: #FFF;
	text-align: center;
	vertical-align: middle;
}
</style>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js" type="text/javascript"></script>
<script src="development-bundle/jquery-1.4.4.js"></script>
 <script type="NHL.js"></script>       

<script type="text/javascript">
//var myVar = setInterval(loadData, 1000);
 
$(document).ready(function(){
	
         loadstats();
      
});

</script>
</head>

<body bgcolor="#000000">
<table width="750" border="0">
  <tr>
    <td width="100"><span class="CENTERMID"><img src="http://dev.sportsnetwork.com/aspdata/nhl2/IMAGES/Defaultlogo.png" alt="" name="imgaway" width="75" height="75" id="imgaway"></span></td>
    <td width="88" class="WHITETEXT" id="awayteamscore">0</td>
    <td width="341"><table width="100%" border="0">
      <tr class="GCPBP">
        <td width="17%"><div align="center" id="txtTime"></div></td>
        <td width="44%"><div align="center" id="txtPeroid"></div></td>
        <td width="10%"><div align="center">1</div></td>
        <td width="9%"><div align="center">2</div></td>
        <td width="10%"><div align="center">3</div></td>
        <td width="10%"><div align="center" id="so">OT</div></td>
      </tr>
      <tr>
        <td><div align="center"><span class="CENTERMID"><img src="http://dev.sportsnetwork.com/aspdata/nhl2/IMAGES/Defaultlogo.png" alt="" name="imgminiaway" width="32" height="32" id="imgminiaway"></span></div></td>
        <td bgcolor="#FFCC66"><div align="center" id="txtaway"></div></td>
        <td bgcolor="#FFFF99"><div align="center" id="periodA1"></div></td>
        <td bgcolor="#FFFF99"><div align="center" id="periodA2"></div></td>
        <td bgcolor="#FFFF99"><div align="center" id="periodA3"></div></td>
        <td bgcolor="#FFFF99"><div align="center" id="periodA4"></div></td>
      </tr>
      <tr>
        <td><div align="center"><span class="CENTERMID"><img src="http://dev.sportsnetwork.com/aspdata/nhl2/IMAGES/Defaultlogo.png" alt="" name="imgminihome" width="32" height="32" id="imgminihome"></span></div></td>
        <td bgcolor="#FFCC66"><div align="center" id="txthome"></div></td>
        <td bgcolor="#FFFF99"><div align="center" id="periodH1"></div></td>
        <td bgcolor="#FFFF99"><div align="center" id="periodH2"></div></td>
        <td bgcolor="#FFFF99"><div align="center" id="periodH3"></div></td>
        <td bgcolor="#FFFF99"><div align="center"></div></td>
      </tr>
      <tr class="GCPBP">
        <td colspan="6"><div align="center" id="txtLoc"></div></td>
      </tr>
    </table></td>
    <td width="107"><span class="CENTERMID"><img src="http://dev.sportsnetwork.com/aspdata/nhl2/IMAGES/Defaultlogo.png" alt="" name="imghome" width="75" height="75" id="imghome"></span></td>
    <td width="92" class="WHITETEXT" id="hometeamscore">0</td>
  </tr>
</table>
<table width="750" border="0">
  <tr class="GCPBP">
    <td><div align="center">Shots</div></td>
    <td><div align="center">Faceoff %</div></td>
    <td><div align="center">Hits</div></td>
    <td><div align="center">Penalties</div></td>
    <td><div align="center">PIM</div></td>
    <td><div align="center"></div></td>
    <td><div align="center">Shots</div></td>
    <td><div align="center">Faceoff %</div></td>
    <td><div align="center">Hits</div></td>
    <td><div align="center">Penalties</div></td>
    <td><div align="center">PIM</div></td>
  </tr>
  <tr>
    <td><div align="center" id="awayShots"></div></td>
    <td><div align="center" id="awayFO"></div></td>
    <td><div align="center" id="awayHits"></div></td>
    <td><div align="center" id="awayPenalties"></div></td>
    <td><div align="center" id="awayPIM"></div></td>
    <td><div align="center"></div></td>
    <td><div align="center" id="homeShots"></div></td>
    <td><div align="center" id="homeFO"></div></td>
    <td><div align="center" id="homeHits"></div></td>
    <td><div align="center" id="homePenalties"></div></td>
    <td><div align="center" id="homePIM">homePIM</div></td>
  </tr>
</table>
<script>
var myVar=setInterval(function(){myTimer()},2000);

function myTimer()
{

refreshsc();
}
</script>
</body>
</html>

Open in new window


Here is external

// JavaScript Document
var QueryString = function () {
	var query_string = {};
	var query = window.location.search.substring(1);
	var vars = query.split("&");
	for (var i=0;i<vars.length;i++) {
		var pair = vars[i].split("=");
		// If first entry with this name
		if (typeof query_string[pair[0]] === "undefined") {
			query_string[pair[0]] = pair[1];
		// If second entry with this name
		} else if (typeof query_string[pair[0]] === "string") {
			var arr = [ query_string[pair[0]], pair[1] ];
			query_string[pair[0]] = arr;
		// If third or later entry with this name
		} else {
			query_string[pair[0]].push(pair[1]);
		}
	} 
	return query_string;
} ();

function refreshsc() {
var xmlPath = '/xml/nhl/scores/real';
	 var xmlGameID = QueryString.gameID; 
$.ajax({
	 
        type: "GET",
        url:  xmlPath+"/"+xmlGameID+ ".xml",
        dataType: "xml",
        success: function(data) {
            var d = $(data);
            var Play = d.find('Play');
           
            var timeleft = Play.attr("TimeLeft")
            $(txtTime).html("Time Remaining" + "   "  + timeleft);
			var location = Play.attr("Location")
			$(txtLoc).html(location);
            d.find('Team').each(function(i,Team){
                var team = $(Team);
                var id = team.attr("ID").toLowerCase();
                var vh = team.attr('vh'); // A or H...
                var sHomeOrAway = vh == 'H' ? 'home' : 'away';
 			$('#img' + "mini" + sHomeOrAway).attr('src', 				'http://images.sportsnetwork.com/nhl/attherink/logos/' + team.attr('ID') + '.png');
                $('#img' + sHomeOrAway).attr('src', 'http://images.sportsnetwork.com/nhl/attherink/logos/' + team.attr('ID') + '.png');
               
            });
        }
    });
}
function loadstats() {
	var xmlPath = '/xml/nhl/scores/real';
	 var xmlGameID = QueryString.gameID; 
$.ajax({
	 
        type: "GET",
        url:  xmlPath+"/"+xmlGameID+ ".xml",
        dataType: "xml",
        success: function(data) {
            var d = $(data);
            var Play = d.find('Play');
           
            var timeleft = Play.attr("TimeLeft")
            $(txttime).html(timeleft);
			var location = Play.attr("Location")
			$(txtLoc).html(location);
            d.find('Team').each(function(i,Team){
                var team = $(Team);
                var id = team.attr("ID").toLowerCase();
                var vh = team.attr('vh'); // A or H...
                var sHomeOrAway = vh == 'H' ? 'home' : 'away';
 $('#' + sHomeOrAway + 'teamscore').html(team.find('Linescore').attr('Score'));

                team.find('LineQuarter').each(function(i2, oLQ){
                    $('#period' + vh + $(oLQ).attr('Prd')).html($(oLQ).attr('score'));
                });

                $('#txt' + sHomeOrAway + 'team').html(team.attr('Fullname'));
                $('#txt' + sHomeOrAway).html(team.attr('name'));

                var oTS = $(Team).find('TeamStats');
                $('#' + sHomeOrAway + 'Shots').html(oTS.attr('Shots'));
                $('#' + sHomeOrAway + 'FO').html(oTS.attr('FaceOffsPct') + '%');
                $('#' + sHomeOrAway + 'Hits').html(oTS.attr('Hits'));
                $('#' + sHomeOrAway + 'Penalties').html(oTS.attr('Penalties'));
				$('#' + sHomeOrAway + 'PIM').html(oTS.attr('PIM'));
				 });
        }
    });
}


 

Open in new window


Thanks EE
0
Comment
Question by:powerztom
  • 2
  • 2
4 Comments
 
LVL 38

Accepted Solution

by:
Tom Beck earned 500 total points
Comment Utility
You have this for the script include:  <script type="NHL.js"></script>

Should be:
 <script type="text/javascript" src="NHL.js"></script>
0
 

Author Closing Comment

by:powerztom
Comment Utility
Thanks Tommyboy I have a follow up question I'll post rather then ask in this ticket. Thanks Again
0
 
LVL 38

Expert Comment

by:Tom Beck
Comment Utility
Fire away!

Thanks for the points.
0
 

Author Comment

by:powerztom
Comment Utility
Tommy Boy I decided to experiment and I solved my follow up question.
Thanks again for the first one.
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Introduction If you're like most people, you have occasionally made a typographical error when you're entering information into an online form.  And to your consternation, the browser remembers the error, and offers to autocomplete your future entr…
SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
In this tutorial viewers will learn how to position items using CSS's three positioning types Create a new HTML document with an internal stylesheet.: Create another div in CSS and name it Absolute : Type "position:absolute;" and "top:10px; left:50p…
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 …

744 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

16 Experts available now in Live!

Get 1:1 Help Now