0

I have a two dimensional array:

If I 'alert' the output as follows I see expected results:

alert(myArray[0][0]['test']);

I am then passing the array to an html form:

$('form#id1 #PassArray').val(myArray);

I am then lisening for the form submission and if I do this:

var received=$('input#PassArray').val();

alert(received[0][0]['test']);

I get output: undefined.

Is it necessary to prepare the array in some way if passing it to a html form?

3
  • You can't set the value of an input box to an array Commented Apr 18, 2013 at 16:18
  • It's a hidden field of the array... so will I have to serialize? Commented Apr 18, 2013 at 16:21
  • Yes, even though its hidden, its still stored the same way normal inputs are Commented Apr 18, 2013 at 16:22

1 Answer 1

1

IIRC, a form input can only have a string for its value.

You could either

  1. Serialize your array into a string with $.param()
  2. Iterate over your array to assign values to individual form fields. The form fields can have the same name with [] appended to the end to treat them as an array, i.e. <input name="array[]" />
  3. Just post the array with AJAX
Sign up to request clarification or add additional context in comments.

2 Comments

Ok I see the issue at hand now, I have set the array_array as a session now so I can access it without having to pass it! Thanks
Sounds like a solid solution. np :D

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.