You can still name the text boxes dynamically with a for loop via php.
Something along the lines of:
(I used the attribute 'id' instead of name)
for(var $i = 0; $i < $num_boxes_selected_by_user; $i++)
{
echo "<input type=\"textbox\" id=\"col' . $i . '\" />";
}
Each input name would look like: col0, col1, col2, col3, etc.
If the selection of how many boxes is not on the same page, you would need to save the value of boxes that the user picked either in a session variable that you could access, as a parameter in your URL string, or as a value in a hidden input field.
Then your page would look something like:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>JS Test</title>
<script language="JavaScript" type="text/javascript">
function computeForm(form) {
var SA = 0;
var SB = 0;
for(var j = 0; j < 2; j++)
{
SA += (parseFloat(document.getElementById("COLA"+j).value));
SB += (parseFloat(document.getElementById("COLB"+j).value));
}
form.SUMA.value = SA;
form.SUMB.value = SB;
}
</script>
</head>
<body>
<center>
<form method=POST>
<table>
<tr>
<td> A</td>
<td> B</td>
</tr>
<tr>
<td><input type="text" size="4" id="COLA0"></td>
<td><input type="text" size="4" id="COLB0"></td>
</tr>
<tr>
<td><input type="text" size="4" id="COLA1"></td>
<td><input type="text" size="4" id="COLB1"></td>
</tr>
<tr>
<td><input type="text" size="4" id="SUMA"></td>
<td><input type="text" size="4" id="SUMB"></td>
</tr>
</table>
<input type="button" value="Compute" onClick=computeForm(this.form)>
</form>
</center>
</body>
</html>
I have a value of 2 in my for loop b/c that's all I have for this demo. You would change that to the variable that you store the user's number of boxes selection.
I hope this helps. 