How to use javascript in javascipt

I need to implement a form like the attached file,

each time I click add button, 1 row will be inserted , the row includes: 1 dropdownlist for inventory category,number of people from/to, and 1 dropdownlist for inventory item,

What I want is : when i choose the first dropdownlist( inventory category in the first column) , the second one will be updated according to its value( in the last column).

Can I do it ?

thanks all,

You can, use javascript for this…

thanks for your reply,This is what I have done for the form in attached file:


        <?php echo CHtml::activeDropDownList($model, "[$id]category", array(0=>'Non diposable',1=>'Disposable'),


                        'ajax' => array(

                        'type'=>'POST', //request type

                        'url'=>CController::createUrl('package/selectInventory'), //url to call.

                         'data' => array('id' => 'js:this.value'),

                        'update'=>'#'.CHtml::activeId($model, '[$id]inventory_id'), //selector to update

                        ))); ?> 

        <?php echo $form->error($model,"[$id]category"); ?> 



        <?php echo $form->textField($model,"[$id]num_of_people_from");?>

        <?php echo $form->error($model,"[$id]num_of_people_from");?>



        <?php echo $form->textField($model,"[$id]num_of_people_to");?>

        <?php echo $form->error($model,"[$id]num_of_people_to");?>        


        <?php echo CHtml::activeDropDownList($model, "[$id]inventory_id", array(0=>'Non diposable',1=>'Disposable'))?> 

        <?php echo $form->error($model,"[$id]inventory_id"); ?> 


in the controller :

public function actionSelectInventory(){



    foreach($data as $value=>$name)


        echo CHtml::tag('option',




ajax works well( ajax is called from controller), but it seems that it can not find the right place to update. I try to viewsource the page in HTML, but can not find selector for that. (add function works well, )

was I wrong ?

Please help me , I got stuck at this one for 2 days