How to set multi-value hidden field from javascript? I have a multi-value text field, the values should be set from javascript on the browser.
For a single value text field, I can just set the value of the hidden field. But for multi-value text field, drupal will only take the first value and omit following values even the browser post more than one value.
I insert some input tag with same name (nearly, see below) under the form using jquery:
&lt;input type=&quot;hidden&quot; name=&quot;field_subscription_id[und][0][value]&quot; value=&quot;52e1c1d99c29ec6fd84698b6&quot; /&gt;
&lt;input type=&quot;hidden&quot; name=&quot;field_subscription_id[und][1][value]&quot; value=&quot;52e1c1d99c29ec6fd84698b6&quot; /&gt;
...

data is POST like this (inspect using dev tool of chrome):
field_subscription_id[und][0][value]=52e1c1d99c29ec6fd84698b6
field_subscription_id[und][1][value]=52e3de349c29ec6fd84698d4
...

After node created, the field field_subscription_id will only have the first value.
So, any idea to make this work? ~thx
EDIT
I define the form from UI, just a normal content type and a text field. I make a ajax request to external site from page, let user select something (from the ajax response), then fill a field of add-node form with the selected ids.
Using the AJAX response, I build a list of &lt;li&gt;, each &lt;li&gt; has a checkbox, the form attribute (HTML5) of the checkbox has been set to the value of form-id of drupal add-node form on this page.
Fields will only appear in the $field_state array if they were there when the form was built. (If you inspect the $_POST array directly you should see your values there.)

The solution: When creating the form add enough fields so you don't need to add any more with js.

If you didn't create the form yourself then use hook_form_alter to add more fields.

If you need to be able to add more fields on the fly then you will have to look into the #ajax property. The examples module has some good examples on that.

Also make sure to use the #default_value, not #value property if you need to set a default value for any of the hidden fields as using #value will lock the value to that and stop the client from being able to make any changes.