<table border="1" cellspacing="0" cellpadding="4">
<tr><td></td><td></td></tr>
<tr><td></td><td></td></tr>
</table>
<script>
var cells = document.getElementsByTagName('td'), a = []
for(var i = 0, len = cells.length; i < len; i++){
a[i] = document.createElement('input')
a[i].onclick = function(){
this.value = 'Clicked!'
}
cells[i].appendChild(a[i])
}
</script>
Почитай
тут. Особенно 4й пункт