By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,089 Members | 1,152 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,089 IT Pros & Developers. It's quick & easy.

trouble changing my array to include for/in structure......

P: n/a
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.

Mar 25 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Hi,

It would be great if you put a link to this not-working page, because
it can be something with where the script is put.

On Mar 25, 3:35 pm, 4An...@gmail.com wrote:
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.

Mar 25 '07 #2

P: n/a
Lee
4A****@gmail.com said:
>
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"
The triple spacing and the need to use a feature that doesn't
really make any sense seem to be a couple of good clues that
this is a school assignment. The "hey guys" and the fact that
you're too lazy to use punctuation or capitalization seem to
further indicate that you're fairly young and ignorant.

Where did the variable "mycars" come from? It looks like
something that might have been part of an example that your
instructor presented in class.
--

Mar 25 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.