Form Dropdownlist Value Onchange

Hi All,

How do I trigger ‘onchange’ only when specific value is selected from the form dropdownlist?

I’m following Zaccaria’s wiki/ in creating a pop-up dialog for user to create new type if it’s not available in the list.

I have the following dropdownlist code in the create form.

How do I trigger ‘onchange’ only when the value ‘addNew’ is selected?


echo $form->dropDownList($model,'type_id', 

                Dropdown::model()->getTypeAsset() + array('addNew'=>'Add New...'),			

                array('onchange'=>"{addDropdown(); $('#dialogDropdown').dialog('open'); return false;}"),				

		array('empty'=>array('prompt'=>'-- Select --'), )



Thank for any help.

How about using current value of the dropdownlist?


  if ($(this).val() == 'addNew')





  return false;


Hi rei,

Thanks, that works. Thanks for the great help. Cheers

user this, works for me

<?php echo $form->dropDownListRow($model,‘source’,listItems), array(‘onchange’=>‘myfunctionforValuecheck(this.value)’, ‘class’=>‘span5’)); ?>


<script type="text/javascript">

function myfunctionforValuecheck(val){


return sometihngs;


return me;



Hi fburhan89,

Thanks for the help. rei’s suggestion was what I’m looking, it’s working fine.