Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Unable to load functions from external Javascript file

Posted on 2014-01-07
4
Medium Priority
?
1,129 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
[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
  • 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

Build and deliver software with DevOps

A digital transformation requires faster time to market, shorter software development lifecycles, and the ability to adapt rapidly to changing customer demands. DevOps provides the solution.

Question has a verified solution.

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

When it comes to write a Context Sensitive Help (an online help that is obtained from a specific point in state of software to provide help with that state) ,  first we need to make the file that contains all topics, which are given exclusive IDs. …
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 transparent/translucent elements using alpha transparency in CSS Start with a normal styled element, such as a div.: Define its "background-color" property as "rgba (255, 255, 255, .5): The numbers in…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

670 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