Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 12 of 12
  1. #1
    New Coder
    Join Date
    Aug 2002
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts

    store array data to hidden input field

    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;

  • #2
    Regular Coder
    Join Date
    Jul 2002
    Location
    Iran
    Posts
    695
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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?!

  • #3
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,037
    Thanks
    0
    Thanked 250 Times in 246 Posts
    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(",");

  • #4
    New Coder
    Join Date
    Aug 2002
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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(",");

  • #5
    Regular Coder
    Join Date
    Jul 2002
    Location
    Iran
    Posts
    695
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #6
    Senior Coder
    Join Date
    Jun 2002
    Location
    41° 8' 52" N -95° 53' 31" W
    Posts
    3,660
    Thanks
    0
    Thanked 0 Times in 0 Posts
    document.yourformname.yourhiddenfieldname.value = test.join("|");//default delimeter is comma if not specified


    to get back:

    test = document.yourformname.yourhiddenfieldname.value.split("|");
    Former ASP Forum Moderator - I'm back!

    If you can teach yourself how to learn, you can learn anything. ;)

  • #7
    New Coder
    Join Date
    Aug 2002
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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?

  • #8
    Regular Coder
    Join Date
    Jul 2002
    Location
    Iran
    Posts
    695
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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!
    Last edited by ConfusedOfLife; 10-17-2002 at 11:07 PM.

  • #9
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,037
    Thanks
    0
    Thanked 250 Times in 246 Posts
    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.

  • #10
    New Coder
    Join Date
    Aug 2002
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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?

  • #11
    Regular Coder
    Join Date
    Jul 2002
    Location
    Iran
    Posts
    695
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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?!

  • #12
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,037
    Thanks
    0
    Thanked 250 Times in 246 Posts
    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>


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •