473,407 Members | 2,326 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,407 software developers and data experts.

array of arrays - assigning values to variables inside array !

55
Hi,

Can anyone please advise me on the following. Here I have a bunch of variables in an array. And then those arrays in another array. I want to assign values to those variables in arrays. Is this the correct way to do it?

Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <body>
  3.  
  4. <script type="text/javascript">
  5.  
  6. var a,b,c,d,e,f;
  7. var set1=[a,b,c];
  8. var set2=[d,e,f];
  9. var comboAll=[set1,set2];
  10.  
  11. function initializeVars(){
  12.  
  13.     for (var i=0; i<comboAll.length;i++){
  14.  
  15.         for (var j=0; j<comboAll[i].length;j++){
  16.             comboAll[i][j] = 'Hello ' + j ;
  17.         }    
  18.     }    
  19.  
  20.     document.write('Start wrting variables<br />');    
  21.     document.write(a + '<br />');
  22.     document.write(b + '<br />');
  23.     document.write(c + '<br />');
  24.     document.write(d + '<br />');
  25.     document.write(e + '<br />');
  26.     document.write(f + '<br />');
  27.  
  28.  
  29. }
  30.  
  31. </script>
  32.  
  33. </body>
  34. <input type='button' value='Initilize' onClick='initializeVars();' />
  35. </html> 
  36.  
Best regards
Aug 24 '10 #1
7 2136
Dormilich
8,658 Expert Mod 8TB
first, don’t use document.write() after the page finished loading.
Aug 24 '10 #2
hash4sp
55
@Dormilich
I changed it with a DIV tag. Still doesnt work.
It returns undefined for each variable.

Expand|Select|Wrap|Line Numbers
  1. <div id='results'></div>
  2.  
  3. document.getElementById('results').innerHTML = a + ' ' + b + ' ' + c + ' ' + d + ' ' + e + ' ' + f;
  4.  
regards
Aug 24 '10 #3
Dormilich
8,658 Expert Mod 8TB
of course, you never set them anywhere.
Aug 24 '10 #4
hash4sp
55
Thanks for you reply. I am setting the values for the array variables in the loop. Am i doing something wrong here.

Expand|Select|Wrap|Line Numbers
  1.  
  2. <html>
  3. <body>
  4.  
  5. <script type="text/javascript">
  6.  
  7. var a,b,c,d,e,f;
  8. var set1=[a,b,c];
  9. var set2=[d,e,f];
  10. var comboAll=[set1,set2];
  11.  
  12. function initializeVars(){
  13.  
  14.     for (var i=0; i<comboAll.length;i++){
  15.  
  16.         for (var j=0; j<comboAll[i].length;j++){
  17.             comboAll[i][j] = 'Hello ' + j ;
  18.         }    
  19.     }    
  20.  
  21. document.getElementById('results').innerHTML = a + ' ' + b + ' ' + c + ' ' + d + ' ' + e + ' ' + f;
  22.  
  23.  
  24.  
  25. }
  26.  
  27. </script>
  28.  
  29. </body>
  30. <input type='button' value='Initilize' onClick='initializeVars();' />
  31. <div id='results'></div>
  32. </html> 
  33.  
Aug 24 '10 #5
Dormilich
8,658 Expert Mod 8TB
you don’t. what you’re setting is the comboAll variable, not a to f.
Aug 24 '10 #6
hash4sp
55
@Dormilich

Indeed thanks for your answers.
Then how do I assign values during the loop to those variables from a to f?
Aug 25 '10 #7
Dormilich
8,658 Expert Mod 8TB
you cannot. you would have to assign a to f manually.

you should better think of a way, to tweak the output (admittedly, you have a very abstract example)
Aug 25 '10 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Ben | last post by:
Hi all, This may sound easy but I'm having trouble assigning values to array element. My problem is as follows: m = for o in m: # Here first o is 'Peter'.. I want to do something like this:...
2
by: The Plankmeister | last post by:
Hi there... Is it possible to write an UPDATE or INSERT query, where the new value comes from an array? For example: UPDATE table_a SET column_x = WHERE column_y = ; It's a query (for...
7
by: Matt | last post by:
How do you add up all the values in an array? The length of the array is variable. Is there a built in function?
2
by: Zitan Broth | last post by:
Greetings All, Running pg 7.3.4 and was reading: http://archives.postgresql.org/pgsql-interfaces/2003-09/msg00018.php . Basically want to assign values to an array and then a 2d array. However...
3
by: K. Deepa | last post by:
Hi all, I am using postgresql7.4. How to handle arrays in plpgsql. How can I pass an array. Is it possible to retrieve values from an array by indexing it like argument : '{1,2,3}' Return...
14
by: Eric Bantock | last post by:
Very basic question I'm afraid. Once an array has been declared, is there a less tedious way of assigning values to its members than the following: myarray=8; myarray=3; myarray=4; myarray=0;...
28
by: anonymous | last post by:
I have couple of questions related to array addresses. As they belong to the same block, I am putting them here in one single post. I hope nobody minds: char array; int address; Questions...
1
by: Nightfarer | last post by:
Hello. I have a big trouble using System.Array class (it's the first time I use it) for a software I'm developing. I have a form with a textbox(numbers) and one button (done). Once the number...
6
by: sumuka | last post by:
Hello, I'm doing a project in java and im not able to assign the values which are got from for loop to the 2-dimensional array. Can anyone tell me how to assign the values and print them? the...
9
by: i12know | last post by:
Hi guys, I had some problem inserting values a structure array in C++. I had define for example struct UNITS { unsigned char VariableA; unsigned char VariableB; // the...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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,...
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,...
0
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...
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.