Quick questions Is there Way to Ap开发者_StackOverflow中文版pend a textarea using Cakephp
view code:
<?php echo $ajax->link(
$qnote['Qnote']['subject'],
array(
'controller' => 'qnotes',
'action' => 'view', $qnote['Qnote']['id']
),
array( 'update' => 'Textarea_id')
);
?>
controller Code:
function view($id = null) {
$this->Qnote->id = $id;
$this->set('qnote', $this->Qnote->read());
}
the above code Pulls the information But Replaces the entire Text in the textarea. Is there a way I can just append the textarea with out removing the existing text in the textarea
if possible can somebody point me in the right direction please.
You can try saving the result of your AJAX request to a hidden field and then having it execute and on page javascript function to simply slap the values from the hidden field to the visible text area.
The AJAX helper lets your specify callback functions, so something like this should work:
<?php echo $ajax->link(
$qnote['Qnote']['subject'],
array(
'controller' => 'qnotes',
'action' => 'view', $qnote['Qnote']['id']
),
array( 'update' => 'Textarea_id_hidden', "complete" => "concat_fields()" )
);
?>
and then the JavaScript in the View
<script type="text/javascript">
function concat_fields() {
$('#Textarea_id').val( $('#Textarea_id').val() . $('#Textarea_id_hidden').val() );
}
</script>
Note: My JavaScript example above assumes you're using JQuery, changes will need to be made if you're not.
精彩评论