JS DropDown

Hi everyone,

I was wondering how do you create a dropdown list with an option "Create a new type" and when it is selected, it will shows a textbox on the side. Can it be done with CActiveForm?


<?php echo $form->dropDownList($model, 'vendor_id', $vendor_list) ?>

How can I attached javascript on it? OR I can’t rely on the ActiveForm anymore and need to list down all the HTML code myself?

Thanks a lot.



You can pass a third parameter to the dropDownlist fuction that will hold it’s id/class something like:

<?php echo $form->dropDownList($model, 'vendor_id', $vendor_list, array('class'=>'vendorIDdropDown')) ?>

Then just use Jquery event ‘change’ on that class to capture the event and load new content based on the selection. Something like this:

$('.vendorIDdropDown').change(function() {

  // Run ajax callback to load data based on the selection