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/http://www.yiiframework.com/wiki/145/cjuidialog-for-cre 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?




<?php 

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?




array('onchange'=>"{

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

  {

     addDropdown(); 

     $('#dialogDropdown').dialog('open'); 

  }

  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’)); ?>

and

<script type="text/javascript">

function myfunctionforValuecheck(val){

if(val=="MyValue")

return sometihngs;

else

return me;

}

</script>

Hi fburhan89,

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