Have an array on your page like
var numbers = [];
you can get the contents of the td you have clicked on via
tdElm.innerText
In the code where you select a number, add it to the numbers array
numbers.push(tdElm.innerText);
In the code where you clear a value, remove it from the array (google "javascript remove from array")
That gives you an array of all selected numbers, so use "join" to combine them to a string and show that string in a textbox, or anywhere else you want.
To preempt your next question, no I won't write the code for you, this isn't a code to order website where we do your work, but if you piece the above elements together you should have a solution.