[ Back to install ]

TeamStats

Control TeamStats via JavaScript

This document describes the functions that can be used to control TeamStats via JavaScript. It's presumed that the reader has some knowledge of JavaScript. Anyone who wants to learn more about JavaScript can try Netscape's JavaScript pages or this link collection. Don't worry if you're not interested in this or think it's to complicated. This is an 'extra' feature and it's not necessary to neither understand nor use it.

The first thing you need to do is to give the Applet a name so you can refer to it in your JavaScript code:

<APPLET CODE="embe.ts.TeamStats.class" NAME="TeamStats" WIDTH=560 HEIGHT=480>
                                       ^^^^^^^^^^^^^^^^ 

When you want to call a function you write like this:

document.TeamStats.functionName()

You don't have to use the name "TeamStats", any name will do. At the moment TeamStats has the following functions.

setLeaguefile(String filename)

This function is used to tell TeamStats to load and show a new league. The only argument it takes is the name of the parameterfile that contains the league information. A function call can look like this:

document.TeamStats.setLeaguefile('myleagueargs.txt')

By using this function you can use one Applet to display several different leagues. Here and here are examples of how it might look.

loadLeaguefile(String filename)

Works in the same way as setLeaguefile() with the difference that the new league is not displayed. It's downloaded in the background. This is an example of loadLeaguefile().

showTable(int matches, int rounds, int number)

The function makes TeamStats show Table-mode. The arguments that the function take corresponds to the settings you make in the menus in Table-mode. All arguments should be integers and they have the following meaning:

int matches
0 = all matches, 1 = home matches, 2 = away matches
int rounds
0 = all, 1 = first, 2 = last
int number
The number of matches to show when first or last is selected

If you give an invalid value the setting will not change. Examples of showTable():

Show table without changing any settings:
document.TeamStats.showTable(-1, -1, -1)

Show the current table:
document.TeamStats.showTable(0, 0, -1)

Show table of the last ten matches:
document.TeamStats.showTable(0, 2, 10)

Show table of the six first home matches:
document.TeamStats.showTable(1, 1, 6)

showMatches(string team, int matches, int result)

Shows Match-mode. The arguments of the function are as follow:

string team
The name of the team whose matches are to be shown. The name has to be exactly the same as the name used in the matchfile. If you want to show all matches use the string 'All'.
int matches
0 = all matches, 1 = home matches, 2 = away matches
int result
0 = all, 1 = won, 2 = drawn, 3 = lost

Examples:

Show matches without changing any settings:
document.TeamStats.showMatches(' ', -1, -1)

Show all matches:
document.TeamStats.showMatches('All', -1, -1)

Show all Leeds home matches:
document.TeamStats.showMatches('Leeds', 1, 0)

Show Aston Villas away losses:
document.TeamStats.showMatches('Aston Villa', 2, 3)

showStats()

Shows Statistics-mode. The function has no arguments. Example:
document.TeamStats.showStats()

showCompare(int mode, string hometeam, string awayteam)

Shows Compare-mode. The arguments of the function are as follow:

int mode
0 = statistics, 1 = home/away stats, 2 = previous matches
string hometeam
The name of the hometeam
string awayteam
The name of the awayteam

Examples:

Show compare without changing any settings:
document.TeamStats.showCompare(-1, ' ', ' ')

Show statistics between Derby and Everton:
document.TeamStats.showCompare(0, 'Derby', 'Everton')

Show previous matches between West Ham and Arsenal:
document.TeamStats.showCompare(2, 'West Ham', 'Arsenal')

Here is another example of how you can use showCompare().

Comments

If you try to call a TeamStats-function before the Applet has finished loading some strange results may occur. A way to protect yourself from this is to have a boolean variable that is first set to false and then changed to true in the onLoad-event in <BODY>. The variable is then checked before any function is called. You can se how it works if you study the code of this page.

The use of these functions may vary. The examples given here are just some of the possibilities that exists. The thought behind these functions is that they should provide a way to integrate TeamStats with the rest of the information available. If you, for instance, have pages with information about each team in the league you can have a link that runs TeamStats and shows the matches of the team. It's pretty much up to each and everyone to figure out how to use these functions in the best way.

[ Back to install ]
Copyright © 1998 Mats Bovin.
Comments can be sent to mats-bov@dsv.su.se