...

View Full Version : store array data to hidden input field



knguyen99
10-15-2002, 10:32 PM
How do I store an array data to a hidden input field and retrieve these data back when I need them?

test[0] = 10;
test[1] = 11;
test[3] = 12;

ConfusedOfLife
10-15-2002, 10:46 PM
Why do you wana do that when you can keep them in the array and retrieve them whenever you need them?! Are you sure that you don't want cookies?!

glenngv
10-16-2002, 07:10 AM
maybe he will use it in other pages as well.

to store in hidden field:

document.yourformname.yourhiddenfieldname.value = test.join();//default delimeter is comma if not specified


to get back:

test = document.yourformname.yourhiddenfieldname.value.split(",");

knguyen99
10-16-2002, 02:20 PM
If I do not want default delimeter is comma, can I you some other characters? Can you so me how to do that?



document.yourformname.yourhiddenfieldname.value = test.join();//default delimeter is comma if not specified


to get back:

test = document.yourformname.yourhiddenfieldname.value.split(",");

ConfusedOfLife
10-16-2002, 10:37 PM
Well, I still can't understand why we should hide something that's hidden by default ( an array I mean )! But I think that if you even do not put the delimiter, you won't get an error message.

whammy
10-17-2002, 12:34 AM
document.yourformname.yourhiddenfieldname.value = test.join("|");//default delimeter is comma if not specified


to get back:

test = document.yourformname.yourhiddenfieldname.value.split("|");

knguyen99
10-17-2002, 07:34 PM
I got more than 2 pages openning at the same time. There is only one page available all the time so I can store this array.
Also, I can access and get the storing data to compare the other.

Question:
May be other solutions you can help me out.

1) I get the data from the form initially with loading (can be many fields).
2) Put them on the array.
3) Store in a hidden field.
4) User may modify the data or not. When user select an other link in some other pages. I need to compare the data on the current form to the data storing (hidden field). So I can figure out if this has modified or not.

Is there a way if we can dynamic create an object to store the initial data and compare to the current data?
Compare object, form or something?

ConfusedOfLife
10-17-2002, 10:58 PM
I really suggest that you use cookies, it's much easier and more reliable. Cookies are like files in other languages that you can write your info in them and then retrieve them later. Each document has one cookie and unlike other languages, you can not name them, you just can write into them like this :

document.cookie = "hello";

You can write your entier array into a cookie by a for/while loop and you can even define the expiration date for a cookie, means that your info can stay even if the user closes your page!

glenngv
10-18-2002, 03:10 AM
if you are opening new windows and the array is in the parent window, then you could access the array from the new windows by:

var myArrayName = window.opener.yourArrayName;

where yourArrayName should be declared global in the parent window.

knguyen99
10-18-2002, 02:16 PM
In this case, I am not openning a new window.

I have:

top_nav.jsp (for the menu)
left_nav.jsp (for tree item)
main_nav.jsp (for the main screen display)

these 3 jsp insert into a frame.

If I click the link on the top_nav or left_nav, I need to check for the data of the form on the main_nav.
The main is changing when you select difference link on the tree or from the menu.
On the main display, there is a form with data.

I like to work with cookie, but it does not approve to do it. Is there something similar to the cookie so I can use it.

Do you know any command to compare the object?

ConfusedOfLife
10-20-2002, 11:35 PM
You should have at least one CONSTANT thing if you wana use your array, why don't you put the whole thing inside a new framed page that that framed page be your main ( constant ) page? Now you have a framed page, called A.html for example, just make B.html like this :

<html>
<frameset cols="*">
<frame src="A.html">
</frameset>
</html>



PS.

I like to work with cookie, but it does not approve to do it.

What do you mean?!

glenngv
10-21-2002, 01:52 AM
in your frameset page:

<html>
<head>
<script language="javascript">
var myArray = new Array("item1","item2","item3");
</script>
</head>
<frameset cols="...">
<frame src="...">
<frame src="...">
</frameset>
</html>


then in your pages:

<html>
<head>
<script language="javascript">
var arr = parent.myArray; //get array from frameset page
//other codes here
</script>
</head>
<body>
<form>
...
</form>
</body>
</html>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum