Hello Yiianswers!
Here’s my problem…
In my view I need a textfield from Cactiveform to change when the user selects a value from a dropdownlist.
The dropdownlist gets its value from a model (users) and that value is passed to the controller so I can do some db query.
After i pass that value from the dropdownlist to the controller y get the value I need to return to the view.
The function works and I get the value but I don’t know how to update the text field with that value. here is the code i’m using.
Thanks in advance.
The view:
///This is the Dropdownlist
<div id="droplat "class="row">
<?php
echo $form->labelEx(Users::model(),'De User'); ?>
<?php
echo $form->dropDownList(Users::model(),'users_idusers', CHtml::listData(Users::model()->findAll(), 'users_idusers', 'users_username'),
array(
'prompt'=>'---Select Usuario ---',
'ajax'=>array(
'type'=>'POST', //request type
'url'=>CController::createUrl('getajaxdatafrom'), //url to call.
//'update'=>'#actualizatelat',
'update'=>'#' . CHtml::activeId($model,'log_latfrom'),
'data'=>array('elvalor' => 'js:this.value'),
)));
?>
</div>
///This is the Textfield i need to update with the value $lon from
/// the controller
<div class="row">
<?php echo $form->labelEx($model,'log_latfrom'); ?>
<?php echo $form->textField($model,'log_latfrom',array('size'=>45,'maxlength'=>45)); ?>
<?php echo $form->error($model,'log_latfrom'); ?>
</div>
The Controller:
public function actionGetAjaxDataFrom()
{
$Criteria = new CDbCriteria();
$Criteria->condition = "usergeolog_userid=".$_POST['elvalor'];
$data = Usergeolog::model()->findAll($Criteria);
foreach ($data as $dat) {
$lat=$dat->usergeolog_userlat;
$lon=$dat->usergeolog_userlon;
}
echo CHtml::tag('Log_log_latfrom', array( 'type'=>'text' , 'value' => $lon));
}
as you can see in the controller I use
echo CHtml::tag(‘Log_log_latfrom’, array( ‘type’=>‘text’ , ‘value’ => $lon));
I think this is the problem… I use Log_log_latfrom becouse I believe that is the id of the activetextfield in the view …
Thanks again…