Hi!
This probably is something very simple for you all; I just can’t figure it out.
I have a form with a dropdown list (named FDCode) in which you can select a value. When a value is selected, another field (named Columns of model Crfdstandard) is supposed to change its value to the value found in the Ajax call.
I found the value using the Ajax call but I cannot get the form field to update to the value found!
This is a part of the form holding the dropdown field which performs the Ajax call:
<div class="row">
<?php echo $form->labelEx($model3,'FDCode'); ?>
<?php echo $form->dropDownList($model3,'FDCode', CHtml::listData(FdStandardFormats::model()->findAll(), 'FormatCode', 'FdCode'),
array(
'empty'=> '--Please select--',
'ajax' =>
array(
'type' => 'POST',
'url' => CController::createUrl('Add/fetchSFData'),
'data'=> array('selected_code'=>'js: $(this).val()'),
'update' => '#Crfdstandard_Columns',
)
)
);?>
</div>
<td><!-- Columns -->
<?php echo $form->textField($model3,'Columns',array('size'=>4,'maxlength'=>4)); ?>
</td>
And this is the Ajax function fetchSFData of AddController.php
public function actionFetchSFData()
{
// Get the posted value
$varFromPost = $_POST['selected_code'];
// Get the Attributes using the key
$data=FdStandardFormats::model()->findByPk($varFromPost);
$fieldValue = $data->getAttribute("Columns");
// echo $fieldValue;
//echo CHtml::encode(print_r($fieldValue, true));
echo Chtml::textField('Columns', $fieldValue);
}
It’s the part where I write the value to the field which I cannot get to work. I have tried different approaches to no avail. Your help will be much appreciated! Thanks in advance!