vinz
vinz

Reputation: 348

Setting 2-dimensional array into input hidden field

I have an array which I have another to push into in a loop

array1[ [box1, type1, 10], [box1, type2, 12] ]
array2[ [box2, type1, 10], [box2, type2, 12], [box2, type2, 12] ]

var curArray = new Array();

so in a loop:

var testarray = new Array('box1', 'type1', 10);
curArray.push(testarray);

and I have to post it so I set it in a hidden field. array.push works when I console.log(curArray) but if you set it to a hidden field by

$('hdnField').val(curArray)

it no longer become a multidimensional array.

Is there another way to do this?

Upvotes: 0

Views: 996

Answers (2)

neilsimp1
neilsimp1

Reputation: 1259

You can try JSON.stringify()

$('hdnField').val(JSON.stringify(curArray));

Does this work?

Upvotes: 1

kimwz.kr
kimwz.kr

Reputation: 298

try this:

$('hdnField').val(JSON.stringify(curArray));

Upvotes: 3

Related Questions