Solved

Unable to load functions from external Javascript file

Posted on 2014-01-07
4
1,052 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
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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to read data from SQL server  to sharepoint 2013 ? 3 26
jQuery on Submit 4 44
Wordpress Only run code if on a certain page 11 23
CSS Style Effect 2 10
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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 …
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…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

830 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