Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Unable to load functions from external Javascript file

Posted on 2014-01-07
4
Medium Priority
?
1,153 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 2000 total points
ID: 39762738
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
ID: 39762774
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
ID: 39762790
Fire away!

Thanks for the points.
0
 

Author Comment

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

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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…
Suggested Courses

824 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