Works, but is there a better way?

I was wondering if there is a better way to execute printing a JS variable multiple times within a table. I am working on a webpage for work that needs to work with IE 7. I think I could loop through the document.getElementById(“filename#”).innerHTML instead of writing out the line multiple times. I just can’t seem to figure out how to make this work, or if it is even possible. Any help would be much appreciated.

Here is the JavaScript:


```javascript
function step4() {
var today = new Date();
today.setDate(today.getDate()-1);
var mymonth = today.getMonth();
var mydate = today.getDate();
var myyear = today.getYear();
mymonth = mymonth+1;
if(mydate<=9) mydate = '0'+mydate;
newmonth = mymonth;
if(mymonth=='10') newmonth = 'a';
if(mymonth=='11') newmonth = 'b';
if(mymonth=='12') newmonth = 'c';
if(mymonth<=9) mymonth = '0'+mymonth;

document.getElementById("filename1").innerHTML = newmonth+""+mydate;
document.getElementById("filename2").innerHTML = newmonth+""+mydate;
document.getElementById("filename3").innerHTML = newmonth+""+mydate;
document.getElementById("filename4").innerHTML = newmonth+""+mydate;
document.getElementById("filename5").innerHTML = newmonth + "" + mydate;
document.getElementById("filename6").innerHTML = newmonth + "" + mydate;
document.getElementById("filename7").innerHTML = newmonth + "" + mydate;
document.getElementById("filename8").innerHTML = newmonth + "" + mydate;
document.getElementById("filename9").innerHTML = newmonth + "" + mydate;
document.getElementById("filename10").innerHTML = newmonth + "" + mydate;
document.getElementById("filename11").innerHTML = newmonth + "" + mydate;
document.getElementById("filename12").innerHTML = newmonth + "" + mydate;
document.getElementById("filename13").innerHTML = newmonth + "" + mydate;
document.getElementById("filename14").innerHTML = newmonth + "" + mydate;
document.getElementById("filename15").innerHTML = newmonth + "" + mydate;

  }



Here is one of the table entries that prints out the filename


	<tr>
		<td>Filename</td>
		<td><span id="filename2"></span>_LGSPLT_DETR</td>
		<td><span id="filename3"></span>_LGSPLT_FLNT</td>
		<td><span id="filename4"></span>_LGSPLT_LANS</td>
		<td><span id="filename5"></span>_LGSPLT_GRRP</td>
	</tr>

Using the table DOM nodelists you can access a cell within a table using:

document.getElementsByTagName(‘table’)[0].tBodies[0].rows[2].cells[1].innerHTML = ‘’;

That references the second cell in the third row. By setting up a loop on any of the values you can reference any of the cells within the table.

Thanks @felgall. That is an interesting idea and I will give that a shot.