Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6477647
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T06:58:27+00:00 2026-05-25T06:58:27+00:00

I have an array which I am storing inside an <input type=hidden> . Here

  • 0

I have an array which I am storing inside an <input type="hidden">. Here is my code.

Javascript:

var trees;

// called when the body loads
function BodyOnLoad()
{
  trees = document.getElementById("trees");
  trees.value = new Array();
}

// this is what isn't working
function AddTree()
{
  var i = trees.value.length;

  trees.value[i] = new Array();
  /***/
  trees.value[i]["branches"] = 5;
  trees.value[i]["trunk"]    = 0;
}

HTML: <input type="hidden" name="trees" id="trees" />

In C#, Request.Form["trees"] is not an array. What am I doing wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T06:58:27+00:00Added an answer on May 25, 2026 at 6:58 am

    The HTML form post won’t preserve a javascript object (in this case an Array). You should look at converting your Array to JSON and passing that in the form if you need to preserve the array object.

    Include this script (JSON2) in your page:
    JSON2

    var treesArray;
    
    // called when the body loads
    function BodyOnLoad()
    {
      treesArray = new Array();
    }
    
    function AddTree()
    {
      var tree = new Array();
    
      //branches      
      tree[0] = "5";
    
      //trunk      
      tree[1] = "0";
    
      //name
      tree[2] = "Elm";
    
      treesArray[treesArray.length] = tree;
      document.getElementById("trees").value = JSON.stringify(treesArray);
    }
    

    Then on the server side you will need to convert the JSON to a C# Array using something like this:

    Add reference to JavaScriptSerializer from System.Web.Extensions.dll (.NET 3.5 SP1)

    JavaScriptSerializer serializer = new JavaScriptSerializer();
    string[][] trees = serializer.Deserialize<string[][]>(Request.Form["trees"]);
    
    for(int i = 0; i < trees.Length; i++)
    {
        Console.WriteLine("Branches:" + trees[i][0]);
        Console.WriteLine("Trunk:" + trees[i][1]);
        Console.WriteLine("Name:" + trees[i][2]);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an array of type string which I want to re-use inside a
I have an ArrayList<float[]> inside which I am placing arrays of floats storing the
I have an array of strings in python which each string in the array
I have a .NET string which is Base64 encoded representation of an array of
I have an array which is a list of domains, I want to print
I have an array which contains another array Would I notate it this way?
Lets say I have an array which has n dimensions. Now in order to
If I have a variant array which holds nothing but simple types, and possible
I have a 10x10 array in Java, some of the items in array which
I have an array in PHP which holds a bunch of unix timestamps. As

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.