codice:
<script>
function colora(v) {
  obj = document.getElementById("td"+v)
  dst = document.getElementById("ids")
  if (obj.style.backgroundColor!="red") {
    dst.value += (dst.value=="")?v:","+v;
    obj.style.backgroundColor="red";
  } else {
    obj.style.backgroundColor="white";
  } 
}
</script>
<table><tr>
<td id="td1">Cella 1 </td>
<td id="td2">Cella 2 </td>
</tr></table>
<input name="ids" type="text" id="ids" value="" />
c'e' qualche modifica introdotta per la fase di test... inoltre ho modificato vari id e name: non possono essere costituiti da soli numeri o essere termini riservati... ad esempio "id"

ciao