I’m a newbie, so I’ll bet this is an easy one, but it has me stumped.
I want the background image in a table cell to change when the user presses the space bar within the cell. Here’s the code. The alert box appears, but I keep getting the error message:
document.mytable is not an object.
I’m using IE5. Thanks for any help you can provide, I’ve tried everything I can think of. For example I tried just changing the background of the document rather than referencing the individual cell, but I got the same error.
<HTML>
<HEAD>
<META NAME=”GENERATOR” Content=”Microsoft Visual Studio 6.0″>
<TITLE>Test</TITLE>
<SCRIPT LANGUAGE=javascript>
<!–
function KeyDown(ARow, ACol)
{
if (window.event.keyCode == 32)//Space
{
alert(“Space”);
document.mytable.rows(ARow).cells(ACol).background=”Images/t2_a.gif”;
}
else
{
alert(“NOT Space”);
}
}
//–>
</SCRIPT>
</HEAD>
<BODY>
<FORM>
<TABLE NAME=”mytable” WIDTH=75% BORDER=1 CELLSPACING=1 CELLPADDING=1>
<TR>
<TD background=”Images/t1_a.gif” onkeypress=”KeyDown(0,0)”>Hello</TD>
<TD>there.</TD>
<TD>What</TD>
</TR>
<TR>
<TD>is</TD>
<TD>the</TD>
<TD>problem</TD>
</TR>
<TR>
<TD>with</TD>
<TD>this</TD>
<TD>code?</TD>
</TR>
</TABLE>
</FORM>
</BODY>
</HTML>