[SOLVED] Update an activeTextField through ajax...

Hello again,

Today I want to update an activeTextField based on the selected option of an activeDropDownList through ajax.

But I don't know how to do many things:

Now I have the following:

<div class="simple">

<?php echo CHtml::activeLabelEx($invoice,'currencyID'); ?>

<?php echo CHtml::activeDropDownList($invoice,'currencyID',




      'data'='id=1' // I pass 1 to test, but wath I want to pass es the id property of the selected currency ($currency->id)    

      'update'=>'#'.CHtml::getActiveId($invoice,'exchangeRate')))); ?>


<div class="simple">

<?php echo CHtml::activeLabelEx($invoice,'exchangeRate'); ?>

<?php echo CHtml::activeTextField($invoice,'exchangeRate',array('size'=>10,'maxlength'=>10)); ?>


My currency/getRate does the following:


public function actionGetRate()


   echo $this->loadMoneda()->rate;


But I have two problems with all that:

1.- How I must pass the correct $currency->id (and not the '1' for test), I mean the id of the actual selected currency in the activeDropDownList.

2.- The update does not occur… (actualy if I put 'replace', the activeTextField is replaced for plain text (the velue returned from actionGetRate).

Note: If I run http:://myhost/myproject/index.php?r=currency/getRate&id=1 I get the correct answer. The answer is corrrect if id is 2 or 3, etc, etc.

For your first problem you can use

In the view




In the controller

$id = $_GET['id']

For your second problem ('success' replace 'update')


  '$("#'.CHtml::getActiveId($invoice,exchangeRate).'").attr("value", val)'.



It works!!! Thanks…

Actually, the string continuations I added on formatting the post can be removed. I didn't think of JS allowing whitespace.


    $("#'.CHtml::getActiveId($vehicle,OfficePhone).'").attr("value", val)