title: jQuery - set array values to the input with the same name
body: <p>I was trying to set the array values to the input field named <code>attachments[]</code></p>
  
  <p>I have array stored in js variable <code>attachArray</code></p>
  
  <p>What I have tried is,</p>
  
  <pre><code>$('[name="attachments"]').attr('value', attachArray);
  </code></pre>
  
  <p>or</p>
  
  <pre><code>$('[name="attachments"]').val(attachArray);
  </code></pre>
  
  <p>But getting empty <code>attachments</code> in the controller like this,</p>
  
  <pre><code>array(1) { ["attachments"]=&gt; array(1) { [0]=&gt; string(0) "" } }
  </code></pre>
  
  <p>What I'm doing wrong?</p>
  
  <p><strong>EDIT</strong></p>
  
  <pre><code>&lt;div class="col-md-4"&gt;
      &lt;div class="form-group ticket-align"&gt;
          &lt;label&gt;Attachment&lt;/label&gt;
          &lt;label class="btn btn-primary" data-toggle="modal" data-target="#t-attachment-modal"&gt;
                      Browse&amp;hellip; 
               &lt;input type="hidden" name="attachments[]"&gt;
           &lt;/label&gt;
           &lt;span id="fileList"&gt;&lt;/span&gt;
           &lt;span class="error" id="error-atachments" style='display: none;'&gt;&lt;/span&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>