473,414 Members | 1,711 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,414 software developers and data experts.

two dimensional array

178 100+
Hi,

I have a javascript function that reads in an array from php. Each record is split by a $ and each field is then split by a ^. I was wondering if anyone could help me get this data into a 2d array? Heres what I have so far.

Expand|Select|Wrap|Line Numbers
  1. function drawExisting() {
  2.     if (request.readyState ==4) {
  3.         var returned = request.responseText;
  4.         var recordSplit = returned.split("$");
  5.         var record = recordSplit[0];
  6.         alert(record);
  7.         var fieldSplit = record.split("^");
  8.         var object_name = fieldSplit[0];
  9.         var xpos = fieldSplit[1];
  10.         var ypos = fieldSplit[2];
  11.         var height = fieldSplit[3];
  12.         var width = fieldSplit[4];
  13.         // alert(object_name + " " + xpos + " " + ypos + " " + height + " " + width);
  14.  
  15.         }
  16. }    
This gives me the results for the first record
Aug 21 '08 #1
7 1860
acoder
16,027 Expert Mod 8TB
Loop over recordSplit (an array) and set each fieldSplit (also an array) to an array variable.
Aug 21 '08 #2
cleary1981
178 100+
The problem that is throwing me is that you have to declare the size of the array. Can I declare an array without the size?
Aug 21 '08 #3
acoder
16,027 Expert Mod 8TB
You don't need to declare the size of the array. You can declare it like this:
Expand|Select|Wrap|Line Numbers
  1. var arr = [];
and that's it.
Aug 21 '08 #4
cleary1981
178 100+
Am I on the right track here?

Expand|Select|Wrap|Line Numbers
  1. function drawExisting() {
  2.     if (request.readyState ==4) {
  3.         var record = [];
  4.         var returned = request.responseText;
  5.         var recordSplit = returned.split("$");
  6.         for (i=0; i < record.length; i++) {
  7.             record = recordSplit[i];
  8.             var fieldSplit = record.split("^");
  9.             var object_name = fieldSplit[0];
  10.             var xpos = fieldSplit[1];
  11.             var ypos = fieldSplit[2];
  12.             var height = fieldSplit[3];
  13.             var width = fieldSplit[4];
  14.             alert(object_name + " " + xpos + " " + ypos + " " + height + " " + width);
  15.         }
  16.  
  17.         }
  18. }    
Aug 21 '08 #5
acoder
16,027 Expert Mod 8TB
Sort of. The loop should be on recordSplit, not record. Then use the push() method to add the fieldSplit array to record.
Aug 21 '08 #6
cleary1981
178 100+
I have cracked it. Thanks for your help all the same. Just took a while for the concept to snk in to my thick head. Heres my code.

Expand|Select|Wrap|Line Numbers
  1. function drawExisting() {
  2.     if (request.readyState ==4) {
  3.         cv = document.getElementById("canvas");
  4.         var returned = request.responseText;
  5.         var splitResult = returned.split("$");
  6.         for (var i=0;i<splitResult.length-1;i++) {
  7.             var record = splitResult[i];
  8.             // alert(record);
  9.             var splitRecord = record.split("^");
  10.                 var newObject = document.createElement('div');
  11.                 newObject.id=splitRecord[0];
  12.                 newObject.innerHTML=splitRecord[0];
  13.                 newObject.style.height=splitRecord[3]/10;
  14.                 newObject.style.width=splitRecord[4]/10;
  15.                 newObject.style.top=splitRecord[2];
  16.                 newObject.style.left=splitRecord[1];
  17.                 newObject.onmousedown=function(){grab(this);}
  18.                 cv.appendChild(newObject);
  19.  
  20.         }
  21.         }
  22. }    
Aug 22 '08 #7
acoder
16,027 Expert Mod 8TB
So you didn't need to use a two dimensional array in the end?
Aug 22 '08 #8

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

Similar topics

2
by: ip4ram | last post by:
I used to work with C and have a set of libraries which allocate multi-dimensional arrays(2 and 3) with single malloc call. data_type **myarray =...
6
by: Ruben | last post by:
I'm trying to pass an array of string to a function without knowing how many strings I have beforehand. I've defined one functions as char * insert(char table,int cols, char values); out of...
16
by: rguti | last post by:
Hi, How do I create a two dimensional array? I have created a one dimensional doing this: Dim laFields As ArrayList = New ArrayList How about to do a 2 dimensional?
60
by: Peter Olcott | last post by:
I need to know how to get the solution mentioned below to work. The solution is from gbayles Jan 29 2001, 12:50 pm, link is provided below: >...
5
by: Diffident | last post by:
Hello All, I have a 2-dimensional array that I am storing as a session variable. I have no idea on how I can cast the session variable back to 2-dimensional array. Any pointers? Reference...
22
by: spam.noam | last post by:
Hello, I discovered that I needed a small change to the Python grammar. I would like to hear what you think about it. In two lines: Currently, the expression "x" is a syntax error. I suggest...
6
by: fniles | last post by:
I need to store information in a 2 dimensional array. I understand ArrayList only works for a single dimensional array, is that correct ? So, I use the 2 dimensional array like in VB6. I pass the...
8
by: per9000 | last post by:
Hi all, I have a two-dimensional array of data, f.x int's. We can imagine that the array is "really large". Now I want the data in it and store this in a one-dimensional array. The obvious...
272
by: Peter Olcott | last post by:
http://groups.google.com/group/comp.lang.c++/msg/a9092f0f6c9bf13a I think that the operator() member function does not work correctly, does anyone else know how to make a template for making two...
5
by: nelly0 | last post by:
developing a program that will manipulate noise levels (measured in decibels) that is collected by car manufacturers. These noise levels are produced at seven different speeds by a maximum of six...
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: 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
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
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.