hey guys i am having trouble changing my array code to include a 'for/
in' structure
the code i am trying to change is below:
<script type="text/javascript">
var contents = new Array(3)
for(k=0;k<3;k++){
contents[k] = new Array(2)
}
contents[0][0]="Player Name"
contents[0][1]="Player Number"
contents[1][0]="Shay Given"
contents[1][1]="1"
contents[2][0]="Scott Parker"
contents[2][1]="6"
function changeContent()
{
var r=document.getElementById('myTable').rows
for(i=0; i<r.length; i++){
var x = r[i].cells
for(j=0; j<x.length; j++){
x[j].innerHTML = contents[i][j]
}
}
}
the code i am using currently using changes the contents of a table in
my main page, the code for the table is below:
<table id="myTable" border="1">
<tr>
<td>Player Name</td>
<td>Player Number</td>
</tr>
<tr>
<td>Kiern Dyer</td>
<td>7</td>
</tr>
<tr>
<td>Titus Bramble</td>
<td>3</td>
</tr>
</table>
<form>
<input type="button" onclick="changeContent()" value="View Different
Players">
i tried to change my coding to the following but my change content
does not work after i include the for/in structure in my array:
var x
var contents = new Array(3)
for (x in mycars){
contents[x] = new Array(2)
}
contents[0][0]="Player Name"
contents[0][1]="Player Number"
contents[1][0]="Shay Given"
contents[1][1]="1"
contents[2][0]="Scott Parker"
contents[2][1]="6"
i wanted to know where i am going wrong and if anyone knows how to fix
this???? all help would be much appreciated.