Solved

Passing a javascript array of user created objects to another page

Posted on 2006-12-01
2
183 Views
Last Modified: 2010-04-06
Hi, is there a way to pass an array of user created javascript objects from one page to another?

Here is an example :
<script type="text/javascript">

function myobj(){
this.oneattr = 0;
this.arr = new Array();
}

var test_obj = new myobj();
test_obj.oneattr = "Testing1";
test_obj.arr[0]="Testing2";

var to_pass = new Array();
to_pass[0] = tobj;
</script>

I then want to pass the array "to_pass" to another page and have access to the different attributes of the objects contained in "to_pass".
Is this possible?

Thanks
0
Comment
Question by:rocketsbay
2 Comments
 
LVL 5

Accepted Solution

by:
dasmaer earned 125 total points
ID: 18053349
you can url encode and decode with escape() and unescape(), you can then append the string to a link or form action.

Try doing:

var query= escape(to_pass);

document.getElementById("someDivTag").innerHTML="<a href='http://someplace.org/page.html?obj='"+query+">link</a>";

And then decoding on the target page using unescape:

function getQueryVariable(variable) {
  var query = window.location.search.substring(1);
  var vars = query.split("&");
  for (var i=0;i<vars.length;i++) {
    var pair = vars[i].split("=");
    if (pair[0] == variable) {
      return pair[1];
    }
  }
  alert('Query Variable ' + variable + ' not found');
}

var to_pass = unescape(getQueryVariable(query));

I'm not certain the you can escape an object so you may be forced to serialise it into a list of strings, hopefully this can get you started.
0
 
LVL 41

Expert Comment

by:HonorGod
ID: 18054121
If your object isn't too big, you might store it in a cookie.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Matthew
I am a very big proponent of technology compliance standards and strive to meet such criteria in all of my work. That includes my site, which is 100% XHTML 1.0 compliant as determined by the World Wide Web Consortium. https://www.matthewstevenkel…
JavaScript has plenty of pieces of code people often just copy/paste from somewhere but never quite fully understand. Self-Executing functions are just one good example that I'll try to demystify here.
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

896 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now