So many questions...
1) Did you really want the event to trigger for the entire body of the table? Or did you want it to trigger for a row or cell of the table. If so, you put the 'onclick' event in the wrong place. The only thing you can determine right now is if the table body was clicked on.
2) Is there a form involved in this page somewhere? You generally need a form in order to submit data to another page (aside from Ajax or other tricks).
Assuming you get those two things worked out, it is a fairly simple thing to add or change a form field, with many ways to do it.
Method 1 - Change a form field's value.
<form action="another_page.php" method="post">
. . .
<td id="cell1" onclick="setSelected(this.id)">Some text</td>
<input type="hidden" name="field1" id="field1" value="">
</form>
function setSelected(cellId)
{
// Form field ID you want to change...
var targetField = document.getElementById('field1');
// Change the hidden field's value to "cell1"...
targetField.value = cellId;
// Test that it worked...
alert(targetField.name + "‘s value is now: " + targetField.value);
}
Method 2 - Create a whole new form field using innerHTML...
<form action="another_page.php" method="post">
. . .
<td id="cell1" onclick="setSelected(this.id)">Some text</td>
<div id="formDiv"></div>
</form>
function setSelected(cellId)
{
// Form field ID you want to change...
var targetDiv = document.getElementById('formDiv');
// Add new HTML to the target div...
targetDiv.innerHTML = "<input type='hidden' name='field1' id='field1' value='" + cellId + "' />";
// Test that it worked...
alert("New field has value: " + document.getElementById('field1').value);
}
Etc...