Internet Explorer 5.0, Part II: Hosting Page Code - Doc JavaScript | WebReference

Internet Explorer 5.0, Part II: Hosting Page Code - Doc JavaScript


Hosting Page Code

<HTML>
<HEAD>
<STYLE>
  .tripleBox{behavior:url(xmdbehavior.sct)}
</STYLE>
<SCRIPT LANGUAGE="JavaScript">
var grid = new Array();
grid[1] = new Array();
grid[2] = new Array();
grid[3] = new Array();
function createBoxObject(event) {
  this.id = event.id;
  this.playedBy = "";
}
function rowComplete() {
  var lastPlayedBy = grid[1][1].playedBy;
  if ((lastPlayedBy != "") &&
      (grid[2][1].playedBy == lastPlayedBy) &&
      (grid[3][1].playedBy == lastPlayedBy)) return(true);
  lastPlayedBy = grid[1][2].playedBy;
  if ((lastPlayedBy != "") &&
      (grid[2][2].playedBy == lastPlayedBy) &&
      (grid[3][2].playedBy == lastPlayedBy)) return(true);
  lastPlayedBy = grid[1][3].playedBy;
  if ((lastPlayedBy != "") &&
      (grid[2][3].playedBy == lastPlayedBy) &&
      (grid[3][3].playedBy == lastPlayedBy)) return(true);
  lastPlayedBy = grid[1][1].playedBy;
  if ((lastPlayedBy != "") &&
      (grid[1][2].playedBy == lastPlayedBy) &&
      (grid[1][3].playedBy == lastPlayedBy)) return(true);
  lastPlayedBy = grid[2][1].playedBy;
  if ((lastPlayedBy != "") &&
      (grid[2][2].playedBy == lastPlayedBy) &&
      (grid[2][3].playedBy == lastPlayedBy)) return(true);
  lastPlayedBy = grid[3][1].playedBy;
  if ((lastPlayedBy != "") &&
      (grid[3][2].playedBy == lastPlayedBy) &&
      (grid[3][3].playedBy == lastPlayedBy)) return(true);
  lastPlayedBy = grid[1][1].playedBy;
  if ((lastPlayedBy != "") &&
      (grid[2][2].playedBy == lastPlayedBy) &&
      (grid[3][3].playedBy == lastPlayedBy)) return(true);
  lastPlayedBy = grid[1][3].playedBy;
  if ((lastPlayedBy != "") &&
      (grid[2][2].playedBy == lastPlayedBy) &&
      (grid[3][1].playedBy == lastPlayedBy)) return(true);
}
function handleBoxClick() {
  for (var i = 1; i <= 3; i++)
    for (var j = 1; j <=3; j++)
      if (grid[i][j].id == window.event.id) {
        iIndex = i;
        jIndex = j;
        var lastPlayedBy = window.event.playedBy;
      }
  grid[iIndex][jIndex].playedBy = window.event.playedBy;
  if (rowComplete()) {
    alert("The " + lastPlayedBy + " wins");
    window.location.reload();
  }
}
function handleBoxLoad(i,j) {
  grid[i][j] = new createBoxObject(window.event);
}
</SCRIPT>
</HEAD>
<BODY>
<IMG CLASS="tripleBox" x="50" y="50" onBoxClick="handleBoxClick()"
  onBoxLoad="handleBoxLoad(1,1)"> // join with previous line
<IMG CLASS="tripleBox" x="150" y="50" onBoxClick="handleBoxClick()"
  onBoxLoad="handleBoxLoad(2,1)"> // join with previous line
<IMG CLASS="tripleBox" x="250" y="50" onBoxClick="handleBoxClick()"
  onBoxLoad="handleBoxLoad(3,1)"> // join with previous line
<IMG CLASS="tripleBox" x="50" y="150" onBoxClick="handleBoxClick()"
  onBoxLoad="handleBoxLoad(1,2)"> // join with previous line
<IMG CLASS="tripleBox" x="150" y="150" onBoxClick="handleBoxClick()"
  onBoxLoad="handleBoxLoad(2,2)"> // join with previous line
<IMG CLASS="tripleBox" x="250" y="150" onBoxClick="handleBoxClick()"
  onBoxLoad="handleBoxLoad(3,2)"> // join with previous line
<IMG CLASS="tripleBox" x="50" y="250" onBoxClick="handleBoxClick()"
  onBoxLoad="handleBoxLoad(1,3)"> // join with previous line
<IMG CLASS="tripleBox" x="150" y="250" onBoxClick="handleBoxClick()"
  onBoxLoad="handleBoxLoad(2,3)"> // join with previous line
<IMG CLASS="tripleBox" x="250" y="250" onBoxClick="handleBoxClick()"
  onBoxLoad="handleBoxLoad(3,3)"> // join with previous line
</BODY>
</HTML>

http://www.internet.com


Created: August 11, 1998
Revised: August 11, 1998

URL: http://www.webreference.com/js/column23/code1.html