codetoad.com
  ASP Shopping CartForum & BBS
  - all for $20 from CodeToad Plus!
  
  Home || ASP | ASP.Net | C++/C# | DHTML | HTML | Java | Javascript | Perl | VB | XML || CodeToad Plus! || Forums || RAM 
Search Site:
Search Forums:
  problem to populate tables dynamically  sam68 at 13:45 on Friday, February 09, 2007
 

Hi,
Hi ,
I would like to dynamically populate tables
var bloc = new Array();which contain nested arrays(with constant size)

bloc[0]= new array(10);
bloc[1]= new array(10);
// till bloc[k]

The T table contening my values are constitued from inner array with different

lengths
var T= new Array();
T[0], T[1], T[2],till T[n]


I start to fill the bloc[0] with T[0] and if the length of T[0] is smaller than 10 I

go on with T[1]
But I have the constraint to have unique element per bloc
I have already checked than the individual table T[0], T[1], T[n]...have unique

elements

for exemple
T[0]= ['1','2','3','4','5','6','20']; //i element
T[1]= ['30','20','10','11'];
then bloc[0]should be['1','2','3','4','5','6','20','30','10','11']
[code]
function Test(){
var k = 0; //counter of block
var j=0;// loop in block

var n=0; //counter of nested T
var i=0;// loop in T[]
var found;

bloc[0][0]=T[0][0]; //initialisation: the first element in the first

bloc come from the first elemt of T[0]

for (i=0; i<(T[n].length);i++){ //i is the counter of element in T[]

if(i%10==0)k++; //if already 10 elements in the block

then a new bloc created

if (bloc[k][j] == T[n]) {
si element found do nothing
found = true;
//break;
}

if (!found){
bloc[k][bloc[k].length] = T[n];
// then put it in the block
}

j++;
}

n++;
alert(bloc);
}
[/code]
The function didnot work
Problem with loop?
many thanks for your ideas


  Re: problem to populate tables dynamically  sam68 at 07:22 on Saturday, February 10, 2007
 

The problem is solved with the following function

for (var i=0; i<T.length; ++i) {
for (var j=0; j<T.length; ++j) {
bloc[bloc.length - 1].push(T[j]);
if (bloc[bloc.length - 1].length == 10)
bloc[bloc.length] = [];
//alert(bloc);
}
}








CodeToad Experts

Can't find the answer?
Our Site experts are answering questions for free in the CodeToad forums








Recent Forum Threads
•  What`s wrong with this code?
•  Re: problem to populate tables dynamically
•  passing data using multiple form styles
•  Re: beginnner looping help
•  Re: how to use recursion to convert to binary....
•  time taking to render menu
•  How to measure a Web Page`s Size through javascript?
•  Re: array copy
•  Can javascript preload swf files?


Recent Articles
ASP GetTempName
Decode and Encode UTF-8
ASP GetFile
ASP FolderExists
ASP FileExists
ASP OpenTextFile
ASP FilesystemObject
ASP CreateFolder
ASP CreateTextFile
Javascript Get Selected Text


© Copyright codetoad.com 2001-2007