Cake PHP change value of hidden form item by javascript -


i have below cake php form in view:

<?php $form_id = 'message_form ' + $profile_id ?>      <?php echo $this->form->create('post', array('id' => $form_id, 'url' => array('app' => true, 'controller' => 'messages', 'action' => 'new', $profile_id))); ?>       <?php echo $this->form->input('text', array('type' => 'textarea', 'class' => 'form-control', 'label' => false,  'data-validate' => 'not-empty', 'name' => 'data[message][content]', 'placeholder' => 'reply...')); ?>       <?php echo $this->form->input('hidden', array('type' => 'hidden', 'class' => 'form-control', 'label' => false,  'name' => 'data[message][parent_id]', 'value' => 1)); ?>        <div class="message-reply-options">           <a href="#"><i class="fa fa-camera"></i></a>           <a href="#"><i class="fa fa-paperclip"></i></a>&nbsp;           <a href="#" class="empty-textarea"><i class="fa fa-trash"></i></a>&nbsp;           <span class="pull-right">                <?php echo $this->form->submit('send', array('class' => 'form-control')); ?>           </span>       </div> <?php echo $this->form->end(); ?> 

this works fine, need able change hidden fields value via javascript depending on user else on page.

below current javascript using this, not change value (but gives no error either).

var newestmessage = response.childmessage[response.childmessage.length-1]; var parentid =  newestmessage.parent_message_id; document.getelementsbyname('data[message][parent_id]').value = $parentid; 

this have been comment, since don't have enough reputation...

i guess trying change/assign value hidden field on particular, action. assume click event.

jquery required

$('.classnameofclickableobjt').clilck(function(){    $('input[name="data[message][parent_id]"]').val(parentid);    /*another alternative, might assign attribute,        $('input[name="data[message][parent_id]"]').attr('value', parentid); */ }) 

Comments