spacer

Webref WebRef   Sitemap · Experts · Tools · Services · Newsletters · About i.com

home / experts / javascript / column23


Hosting Page Code

Developer News
Microsoft Shows Off Silverlight 4, IE9 Plans
Metasploit Expands Vulnerability Test Framework
HyperCard Reborn?

<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

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs

webref The latest from WebReference.com Browse >
Rolling Out Your Own HTML Application Version Control · HTML 5: Client-side Storage · Working with Ajax Server Extensions
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Wi-Fi Product Watch, November 2009 · Chip Market Recovering From '08 Collapse · Low-Cost Tools to Kickstart Your New Business


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

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