User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the JavaScript / DHTML / AJAX section within the Web Development category of DaniWeb, a massive community of 373,490 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,881 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JavaScript / DHTML / AJAX advertiser: Lunarpages Web Hosting

Pass a 2D-array with AJAX

Join Date: Jun 2006
Location: Sweden
Posts: 45
Reputation: Oxiegen is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 2
Oxiegen Oxiegen is offline Offline
Light Poster

Help Pass a 2D-array with AJAX

  #1  
Dec 12th, 2007
Hi, all!

Here's another one that's starting to boggle my mind.

I have a form that, with a button, adds a bunch of text-fields in a tablerow.
For every press of the button another row is added. This works in both IE and FF. No probs.

When pressing another button, Register, the information in the form is to be stored in a db.
In the javascript funktion assigned to this button I have a loop that goes through the dynamically created rows of text-fields, and stores the values in variables.
These vars is then passed to an ajax-function.

I have tried with calling the function once in every iteration of the loop. But if you have a bunch or rows, 9 or more, only a few rows of information is stored, 3 or less. Like this:
for (i = 0; i < nrapps; i++) {			
   var appnr = document.Form1.elements['txtAppNr' + id].value;
   var floor = document.Form1.elements['txtFloor' + id].value;
   var unitplac = document.Form1.elements['txtUnitPlac' + id].value;
   var consid = document.Form1.elements['txtConsID' + id].value;
   var unitnr = document.Form1.elements['txtUnitNr' + id].value;
   var unitset = document.Form1.elements['txtUnitSet' + id].value;
   var fuse = document.Form1.elements['txtFuse' + id].value;
   var customer = document.Form1.elements['txtCustomer' + id].value;
   var dob = document.Form1.elements['txtDOB' + id].value;
   <ajaxcode>.CB_Function(regid,appnr,floor,unitplac,consid,unitnr,unitset,fuse,customer,dob,ServerSide_Callback2);
   if (On_Error == true) { return; }
   id++;
}
So my thought was to store the information in a 2D-array and then pass that array to the ajax-function in order to let that function in turn store the information to the db in it's own loop.
for (i = 0; i < arrSize ; i++) {			
   arrApps[i][0] = document.Form1.elements['txtAppNr' + id].value;
   arrApps[i][1] = document.Form1.elements['txtFloor' + id].value;
   arrApps[i][2] = document.Form1.elements['txtUnitPlac' + id].value;
   arrApps[i][3] = document.Form1.elements['txtConsID' + id].value;
   arrApps[i][4] = document.Form1.elements['txtUnitNr' + id].value;
   arrApps[i][5] = document.Form1.elements['txtUnitSet' + id].value;
   arrApps[i][6] = document.Form1.elements['txtFuse' + id].value;
   arrApps[i][7] = document.Form1.elements['txtCustomer' + id].value;
   arrApps[i][8] = document.Form1.elements['txtDOB' + id].value;
   if (On_Error == true) { return; }
   id++;
}
<ajaxcode>.CB_Function(arrApps,nrapps,ServerSide_Callback2);
I've read that you can pass an array in the form of an object. But how do I turn this 2D-array into an object that can be passed? (I'm using AjaxPro by Michael Schwarz)
AddThis Social Bookmark Button
Reply With Quote  
All times are GMT -4. The time now is 5:51 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC