Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

img src="" how 2 not show X or other 1

Status
Not open for further replies.

eequalsmc2plus1

Programmer
Aug 26, 2002
28
ZA
Hey,

Anyone know a way that I can have a table and when a cell in the table is clicked a picture is loaded into the cell.

I wrote this code, but the cells dont have pictures in them before they are clicked and my code puts those boxes with little x's in the cells. I need them to be completely empty, actually got a picture on the background of the table so the x's screw it up. Was thinking of putting a clear gif file as the picture of each cell before they are clicked, but that cant be the best was.

Please help ... thanks, heres the code I wrote so far.


<HTML>
<HEAD>
</HEAD>
<BODY>
<TABLE>
<tr>
<td width=52 height=48>
<A href=&quot;javascript:yourChoice('A')&quot;><IMG name=&quot;A&quot; height=48 src=&quot;&quot; width=52 border=0></A>
</td>
<td width=52 height=48>
</td>
<td width=52 height=48>
</td>
<td width=52 height=48>
<A href=&quot;javascript:yourChoice('B')&quot;><IMG name=&quot;B&quot; height=48 src=&quot;&quot; width=52 border=0></A>
</td>
<td width=52 height=48>
</td>
<td width=52 height=48>
</td>
<td width=52 height=48>
<A href=&quot;javascript:yourChoice('C')&quot;><IMG name=&quot;C&quot; height=48 src=&quot;&quot; width=52 border=0></A>
</td>
</tr>
</TABLE>
</BODY>
</HTML>
<SCRIPT language=JavaScript>
var temp = &quot;&quot;;
var ok = 0;
var A = &quot;&quot;;
var B = &quot;&quot;;
var C = &quot;&quot;;

var current = 1;

function yourChoice(chName) {
temp = chName;
checkspace();
if (ok == 1){
document.images[chName].src = &quot;pics/2.jpg&quot;;
} else {
alert(&quot;Theres a piece there already fool.&quot;);
}
}

function checkspace(){
ok = 0;
if ((temp == &quot;A&quot;)&&(A == &quot;&quot;)) {
ok = 1;
A = current;
}
if ((temp == &quot;B&quot;)&&(B == &quot;&quot;)) {
ok = 1;
B = current;
}
if ((temp == &quot;C&quot;)&&(C == &quot;&quot;)) {
ok = 1;
C = current;
}
}
</SCRIPT>

 
Make these changes:
Code:
<a href=&quot;javascript:yourChoice('A')&quot;><img name=&quot;A&quot; height=48 src=&quot;&quot; width=52 border=&quot;0&quot; onError=&quot;this.style.visibility='hidden'&quot;></a>

and

Code:
      if (ok == 1){
         document.images[chName].visibility = &quot;visible&quot;;
         document.images[chName].src = &quot;pics/2.jpg&quot;;
      } else {
         alert(&quot;Theres a piece there already fool.&quot;);
      }
 
Thanks Supra, works perfect.
you 4got little bit though, but figured it out.

document.images[chName].STYLE.visibility = &quot;visible&quot;;

 
Oops! I shouldn't help people early in the morning :p
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top