title: Cake PHP change value of hidden form item by javascript
body: <p>I have the below cake php form in my view:</p>
  
  <pre><code>&lt;?php $form_id = 'message_form ' + $profile_id ?&gt;
  
      &lt;?php echo $this-&gt;Form-&gt;create('Post', array('id' =&gt; $form_id, 'url' =&gt; array('app' =&gt; true, 'controller' =&gt; 'messages', 'action' =&gt; 'new', $profile_id))); ?&gt;
  
       &lt;?php echo $this-&gt;Form-&gt;input('text', array('type' =&gt; 'textarea', 'class' =&gt; 'form-control', 'label' =&gt; false,  'data-validate' =&gt; 'not-empty', 'name' =&gt; 'data[Message][content]', 'placeholder' =&gt; 'Reply...')); ?&gt;
  
       &lt;?php echo $this-&gt;Form-&gt;input('hidden', array('type' =&gt; 'hidden', 'class' =&gt; 'form-control', 'label' =&gt; false,  'name' =&gt; 'data[Message][parent_id]', 'value' =&gt; 1)); ?&gt;
  
        &lt;div class="message-reply-options"&gt;
            &lt;a href="#"&gt;&lt;i class="fa fa-camera"&gt;&lt;/i&gt;&lt;/a&gt;
            &lt;a href="#"&gt;&lt;i class="fa fa-paperclip"&gt;&lt;/i&gt;&lt;/a&gt;&amp;nbsp;
            &lt;a href="#" class="empty-textarea"&gt;&lt;i class="fa fa-trash"&gt;&lt;/i&gt;&lt;/a&gt;&amp;nbsp;
            &lt;span class="pull-right"&gt;
                 &lt;?php echo $this-&gt;Form-&gt;submit('Send', array('class' =&gt; 'form-control')); ?&gt;
            &lt;/span&gt;
        &lt;/div&gt;
  &lt;?php echo $this-&gt;Form-&gt;end(); ?&gt;
  </code></pre>
  
  <p>This works fine, however I need to be able to change the hidden fields value via javascript depending on something the user does else where on the page.</p>
  
  <p>Below is my current javascript I am using for this, however it does not change the value (but gives no error either).</p>
  
  <pre><code>var newestmessage = response.ChildMessage[response.ChildMessage.length-1];
  var parentid =  newestmessage.parent_message_id;
  document.getElementsByName('data[Message][parent_id]').value = $parentid;
  </code></pre>