Yii - How To Display The Name In An Array Containg Name=>Value Pair

I’m new to yii framework. I have created a simple dropdownlist.

    echo $form->dropDownList($model, 'max_cost', array('2'=>'Yes', '0'=>'No'), 


                                              'empty'=>'Choose one', 




Now when I select Yes, the alert box will display Yes and when i select no the alert box will display no.

Suppose I want to display 2 when I select yes and 0 when I select no . What should I do for this? item.value displays the RHS I want to display LHS

I tried alert(value), is it the right way to do it.

Well, you can do whatever you want in onchange, since it’s just a JS callback.

I suppose you are looking for selectedIndex instead of item.value.

Did it work?