473,421 Members | 1,650 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,421 software developers and data experts.

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

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
2 1416
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Jens Mittag | last post by:
Hi! In my code, I have an array of a structure, which I want to save to a binary file. When the array is just created, everything works fine, but when I change contents of the array, saving...
36
by: Eric Laberge | last post by:
Hi! I'm working on automatically generated code, and need to assign arrays. memcpy is an obvious solution, but it becomes complicated to use in the context I'm working on, ie.: I could use it...
7
by: Sam | last post by:
Hello I have a structure called Company. struct Company { char *employee; char *employee_address; }; I want to build an array of this structure but the number of employees will change...
0
by: Adam Warner | last post by:
Hi all, One cannot return a pointer to an array in C since there are no first class array types. But one can return a pointer to an incomplete array via the illegal but widely supported zero...
8
by: redefined.horizons | last post by:
I would like to have an array declaration where the size of the array is dependent on a variable. Something like this: /* Store the desired size of the array in a variable named "array_size". */...
11
by: skumar434 | last post by:
Hi everybody, I am faceing problem while assigning the memory dynamically to a array of structures . Suppose I have a structure typedef struct hom_id{ int32_t nod_de; int32_t hom_id;
2
by: redeagle | last post by:
I'm having trouble assigning values to a structure that has been created in a Module. When I run the Main Subroutine it errors out when I try to assign a value to the Id1 array with "Object not...
44
by: svata | last post by:
Hello, I wonder how to resize such array of structures using realloc()? #include <stdio.h> #include <stdlib.h> #define FIRST 7 typedef struct { char *name;
6
by: Active8 | last post by:
Hi: This prob "magically" stopped and I'm not sure if I can recreate it, but thought I'd share it and maybe learn something. #include "stdafx.h" #include <stdlib.h> #include <math.h>...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.