• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Tim Cooke
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
Saloon Keepers:
  • Piet Souris
Bartenders:

javascript array object to parameter

 
Ranch Hand
Posts: 798
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a javascript array, I want to append to request parameter, how could I do this ?

like,
var myArray = new Array();
var people = new Object();
people.name="Tom";
people.age="30";
myArray[0]=people;

var people1 = new Object();
people1.name="Bob";
people1.age="50";
myArray[1]=people1;

Then my paramter will be
?people[0].name=tom&people[0].age=50&people[1].name=bob&people[1].age=50.

So far, my way is , use hidden value, like
document.write("<input name='people[0].name' type='hidden' value='tom'>");
....

But I think this way not efficient and use lots of memory. Do you have better way?

Thanks
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Look for buildQueryString here: http://www.oracle.com/technology/pub/articles/cioroianu-ajax-data.html
 
Edward Chen
Ranch Hand
Posts: 798
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks. But I can't use AJAX.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Edward, did you have a look at the function called buildQueryString ?
Don't you think that it is a simple Javascript function ?
Copy/Paste that function and get rolling
 
Edward Chen
Ranch Hand
Posts: 798
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks, Satou,
My problem is not located in how to make a right-format query but in how to append an array object to query when submiting.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry Edward, that function would not do the work then.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic