Im sure this is a simple 5 second fix, but also sure im making rookie mistakes. I want to pass an image from a table to the function, and if the cell clicked contains the image, then i wish to clear that image and replace with a blank then randomly assign the image to a new cell, here is the code so far: function highlight(cell){ oncell=false switch(cell) { case "cell_10" : if(document.all.cell_10.innerHTML=="<img src=http://www.zantarni.com/templates/icons/diamond.gif></img>"){document.all.cell_10.innerHTML=" ";oncell=true;} break ; case "cell_11" : if(document.all.cell_11.innerHTML=="<img src=http://www.zantarni.com/templates/icons/diamond.gif></img>"){document.all.cell_11.innerHTML=" ";oncell=true;} break ; case "cell_12" : if(document.all.cell_12.innerHTML=="<img src=http://www.zantarni.com/templates/icons/diamond.gif></img>"){document.all.cell_12.innerHTML=" ";oncell=true;} break ; case "cell_13" : if(document.all.cell_13.innerHTML=="<img src=http://www.zantarni.com/templates/icons/diamond.gif></img>"){document.all.cell_13.innerHTML=" ";oncell=true;} break ; case "cell_14" : if(document.all.cell_14.innerHTML=="<img src=http://www.zantarni.com/templates/icons/diamond.gif></img>"){document.all.cell_14.innerHTML=" ";oncell=true;} break ; case "cell_15" : if(document.all.cell_15.innerHTML=="<img src=http://www.zantarni.com/templates/icons/diamond.gif></img>"){document.all.cell_15.innerHTML=" ";oncell=true;} break ; case "cell_16" : if(document.all.cell_16.innerHTML=="<img src=http://www.zantarni.com/templates/icons/diamond.gif></img>"){document.all.cell_16.innerHTML=" ";oncell=true;} break ; case "cell_17" : if(document.all.cell_17.innerHTML=="<img src=http://www.zantarni.com/templates/icons/diamond.gif></img>"){document.all.cell_17.innerHTML=" ";oncell=true;} break ; case "cell_18" : if(document.all.cell_18.innerHTML=="<img src=http://www.zantarni.com/templates/icons/diamond.gif></img>"){document.all.cell_18.innerHTML=" ";oncell=true;} break ; case "cell_19" : if(document.all.cell_19.innerHTML=="<img src=http://www.zantarni.com/templates/icons/diamond.gif></img>"){document.all.cell_19.innerHTML=" ";oncell=true;} break ; } if (oncell==true) { var r=Math.round(90*Math.random()) +10; // 90 = 0-89 +10 = 10-99 switch(r) { case 10 : document.all.cell_10.innerHTML="<img src=http://www.zantarni.com/templates/icons/diamond.gif></img>"; break ; case 11 : document.all.cell_11.innerHTML="<img src=http://www.zantarni.com/templates/icons/diamond.gif></img>"; break ; case 12 : document.all.cell_12.innerHTML="<img src=http://www.zantarni.com/templates/icons/diamond.gif></img>"; break ; case 13 : document.all.cell_13.innerHTML="<img src=http://www.zantarni.com/templates/icons/diamond.gif></img>"; break ; case 14 : document.all.cell_14.innerHTML="<img src=http://www.zantarni.com/templates/icons/diamond.gif></img>"; break ; case 15 : document.all.cell_15.innerHTML="<img src=http://www.zantarni.com/templates/icons/diamond.gif></img>"; break ; case 16 : document.all.cell_16.innerHTML="<img src=http://www.zantarni.com/templates/icons/diamond.gif></img>"; break ; case 17 : document.all.cell_17.innerHTML="<img src=http://www.zantarni.com/templates/icons/diamond.gif></img>"; break ; case 18 : document.all.cell_18.innerHTML="<img src=http://www.zantarni.com/templates/icons/diamond.gif></img>"; break ; case 19 : document.all.cell_19.innerHTML="<img src=http://www.zantarni.com/templates/icons/diamond.gif></img>"; break ; } } } --></script> </head> <body> <table border="1" align="center" cellspacing="0" cellpadding="0"> <tr> <td id="cell_10" onclick="highlight('cell_10');return true;"><img src=http://www.zantarni.com/templates/icons/diamond.gif></img></td> <td id="cell_11" onclick="highlight('cell_11');return true;"> </td> <td id="cell_12" onclick="highlight('cell_12');return true;"> </td> <td id="cell_13" onclick="highlight('cell_13');return true;"> </td> <td id="cell_14" onclick="highlight('cell_14');return true;"> </td> <td id="cell_15" onclick="highlight('cell_15');return true;"> </td> <td id="cell_16" onclick="highlight('cell_16');return true;"> </td> <td id="cell_17" onclick="highlight('cell_17');return true;"> </td> <td id="cell_18" onclick="highlight('cell_18');return true;"> </td> <td id="cell_19" onclick="highlight('cell_19');return true;"> </td> </tr> PHP: the current issue is that the first half of the function is not recognising the image but the second half works fine.
you should use img.src instead of innerHTML, just good practice to do things with the least amount of code possible.
What ^^^ said. But if you plan to keep things as they are, you need to change all your "src" line formats from: "<img src=http://www.zantarni.com/templates/icons/diamond.gif></img>" To "<img src=\"http://www.zantarni.com/templates/icons/diamond.gif\" />" (note the "" around the src attribute, and the self-closing img tag)