tpeck
08-14-2003, 10:53 AM
Dear all,
I am trying to make a simple wordsearch program. The user finds the word in a grid of letters and clicks on the letters of the discovered word. The letters are highlighted when clicked.
But I want that when an image is clicked it changes to another image until clicked a second time, in which case it returns to the first image.
I am nearly there, but cannot see how to make the code compact enough to allow for any number of letters being clicked on and off.
My example is for a simple 3 x 3 grid, but I can only get the first letter to switch.
*********************************
This works (sort of):
<html>
<head>
<title>wordsearch</title>
<script language="javascript">
function swap(imgname) {
obj = document.images[imgname];
obj.src = (obj.src.indexOf('off')==-1 )? image/n_off.gif" : image/n_on.gif";
}
</script>
</head>
<body>
<table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse">
<tr>
<td align="center" bgcolor="#CCCCCC" width="20" height="20">
<a href="#" onClick="swap("sortarrow"); return false;">
<img name="sortarrow" src="../../img/n_off.gif" border="0" width="19" height="26"></a></td>
<td align="center" bgcolor="#CCCCCC" width="20" height="20">E</td>
<td align="center" bgcolor="#CCCCCC" width="20" height="20">B</td>
</tr>
<tr>
<td align="center" bgcolor="#CCCCCC" width="20" height="20">O</td>
<td align="center" bgcolor="#CCCCCC" width="20" height="20">G</td>
<td align="center" bgcolor="#CCCCCC" width="20" height="20">L</td>
</tr>
<tr>
<td align="center" bgcolor="#CCCCCC" width="20" height="20">V</td>
<td align="center" bgcolor="#CCCCCC" width="20" height="20">N</td>
<td align="center" bgcolor="#CCCCCC" width="20" height="20">N</td>
</tr>
</table>
</body>
</html>
*****************************************
Many thanks,
Terry
I am trying to make a simple wordsearch program. The user finds the word in a grid of letters and clicks on the letters of the discovered word. The letters are highlighted when clicked.
But I want that when an image is clicked it changes to another image until clicked a second time, in which case it returns to the first image.
I am nearly there, but cannot see how to make the code compact enough to allow for any number of letters being clicked on and off.
My example is for a simple 3 x 3 grid, but I can only get the first letter to switch.
*********************************
This works (sort of):
<html>
<head>
<title>wordsearch</title>
<script language="javascript">
function swap(imgname) {
obj = document.images[imgname];
obj.src = (obj.src.indexOf('off')==-1 )? image/n_off.gif" : image/n_on.gif";
}
</script>
</head>
<body>
<table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse">
<tr>
<td align="center" bgcolor="#CCCCCC" width="20" height="20">
<a href="#" onClick="swap("sortarrow"); return false;">
<img name="sortarrow" src="../../img/n_off.gif" border="0" width="19" height="26"></a></td>
<td align="center" bgcolor="#CCCCCC" width="20" height="20">E</td>
<td align="center" bgcolor="#CCCCCC" width="20" height="20">B</td>
</tr>
<tr>
<td align="center" bgcolor="#CCCCCC" width="20" height="20">O</td>
<td align="center" bgcolor="#CCCCCC" width="20" height="20">G</td>
<td align="center" bgcolor="#CCCCCC" width="20" height="20">L</td>
</tr>
<tr>
<td align="center" bgcolor="#CCCCCC" width="20" height="20">V</td>
<td align="center" bgcolor="#CCCCCC" width="20" height="20">N</td>
<td align="center" bgcolor="#CCCCCC" width="20" height="20">N</td>
</tr>
</table>
</body>
</html>
*****************************************
Many thanks,
Terry