<td onclick="setval(this, 'inp1')">Hello</td>
function setval(cell, id) { document.getElementById(id).value = cell.innerHTML; }