473,796 Members | 2,455 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.getE lementById('myT able').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="change Content()" 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 1452
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.co m 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.getE lementById('myT able').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="change Content()" 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.co m 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
5638
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 results in a file, which doesn't hold the information of the changed array anymore. I dont know why. Here is the code: /*
36
4440
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 but I don't want to. Arrays cannot be assigned in C, but structs can, so I coded the following: #include <stdlib.h>
7
3170
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 thorughout the course the programs use so it will need to
0
367
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 array struct hack: #include <stdlib.h> typedef struct byte_vector_t byte_vector_t;
8
10171
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". */ unsigned short int array_size = 25; /*Declare an array named "numbers" using the variable initialized above. */ unsigned short int numbers;
11
3787
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
960
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 set to instance..." blah blah - even though I have clearly just instanciated it in the previous line. Any ideas? Thanks, John (see code below)
44
5820
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
1828
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> #include <fstream.h//iostream.h
0
9680
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10455
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10228
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10173
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9052
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6788
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5573
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3731
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2925
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.