aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes javascript array object to parameter Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "javascript array object to parameter" Watch "javascript array object to parameter" New topic
Author

javascript array object to parameter

Edward Chen
Ranch Hand

Joined: Dec 23, 2003
Posts: 798
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
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

Look for buildQueryString here: http://www.oracle.com/technology/pub/articles/cioroianu-ajax-data.html


[My Blog]
All roads lead to JavaRanch
Edward Chen
Ranch Hand

Joined: Dec 23, 2003
Posts: 798
Thanks. But I can't use AJAX.
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

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

Joined: Dec 23, 2003
Posts: 798
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

Joined: Nov 24, 2005
Posts: 14688
    
  16

Sorry Edward, that function would not do the work then.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: javascript array object to parameter