Update multiple text field when dropdown list value is changed

I have a form with a dropdownlist and 4 input text fields. I need to set these 4 input text field values according to the dropdown list selected.

The problem now is these 4 input text fields values will only be updated for the first time the dropdown is changed. For the subsequent ajax calls, these input text fields will never be changed, although I can see the backend ajax function does be executed.

Here is my code in the view:



        <?php echo EHtml::activeLabelEx($model,'pub'); ?>


    <td><?php echo EHtml::activeDropDownList($model, 'pub', $model->pub_list,


                'onchange' => EHtml::ajax(


                            'type' => 'POST',

                            'dataType'=> 'json',

                            'url' => CController::createUrl('loadPubConfig'),

                            'replace' => '.adminname, .adminemail, .csemail, .aooemail',




and my codes in the controller:

public function actionLoadPubConfig()


    $pub = array();

    $deptid = $_POST['AddEventForm']['deptid'];

    $pubcode = $_POST['AddEventForm']['pub'];

    $pub = dbAdmin::selectPubByDeptPub($deptid, $pubcode);

    $adminname = (isset($pub['ADMIN']) && !empty($pub['ADMIN']))?$pub['ADMIN']:null;

    $adminemail = (isset($pub['ADMINEMAIL']) && !empty($pub['ADMINEMAIL']))?$pub['ADMINEMAIL']:null;

    $csemail = (isset($pub['CSEMAIL']) && !empty($pub['CSEMAIL']))?$pub['CSEMAIL']:null;

    $aooemail = (isset($pub['AOOEMAIL']) && !empty($pub['AOOEMAIL']))?$pub['AOOEMAIL']:null;

    if(isset($pub) && !empty($pub)) {

        echo "<script language='javascript' type='text/javascript'>








can you try to debug this

if(isset($pub) && !empty($pub)) {

for all subsequent changes and see if it actually returns anything satisfying the if condition

I would do everything in javascript: when the dropdown is changed JS makes the ajax request and when it gets the answer it sets a variable to remember that it shouldn’t update the dropdown again, something like “alreadyDone = true”.

Still I think it’s not a good idea to allow to do something only one time: what if the user makes a mistake and chooses the wrong option? he should reload the page to make another choice…

Can you give the functional requirement/use case behind this? I mean, what exact end user scenario will you use it for?

Hi all, thanks for your input. Sorry for my late reply since was quite busy with other stuffs.


I can see there is different set of values returned by the loadPubConfig function call. I noticed a problem that the form data in the response header (i use chrome -> network to debug) was not changed, but the content for this function call was changed accordingly and it looks correct. But it was not populated to the input fields as wanted.


I need to retrieve the values pre-configured for each options in the dropdown list from db. For example, admin name for option 1 in dropdown is "A", admin name for option 2 in dropdown is "B".