If the example code you've provided is all you have, Try2 and A2 are missing. Otherwise, try maintaining the current 'try' using a global variable instead of looping through your elements to look for the empty one.
Example HTML:
<tr>
<td id="Try1" width="50%">
<div class="tries_container" style="float: left;margin-right: 49px;">
</div>
<div class="tries_container" style="width: 15px;float: left;margin-right: 8px;" id="A1">
</div>
<div class="tries_container" style="width: 15px;float: left;">
</div>
</td>
<td id="Try2" width="50%">
<div class="tries_container" style="float: left;margin-right: 49px;">
</div>
<div class="tries_container" style="width: 15px;float: left;margin-right: 8px;" id="A2">
</div>
<div class="tries_container" style="width: 15px;float: left;">
</div>
</td>
Greatly simplified Javascript:
var tries = 1;
function TryCode(code, gametype, gameid) {
document.getElementById("Try" + tries).innerHTML = "TEST";
tries++;
}
In my example, the "Try2" and "A2" elements are added and "tries" is moved outside of the function becoming the global "tries" variable that I can use throughout my application.
Also, if you need to persist the number of tries through different page loads you will have to put it in the URL as a parameter and retrieve it after the page loads. It appears as though you are passing it as a parameter but you're not retrieving it after the page loads.