php - Get selected value from CHtml::dropDownList
I have a question about Yii framework.
Let's say I have dropdown list like the code listed below.
I need to print selected value and I try to do it with
but nothing happened.
I just need the selected value to store in a variable so I can manipulate it.
<?php echo CHtml::dropDownList('countries', $select = array(), CHtml::listData($countries, 'code', 'name')); ?>
$_POSTvar is corresponding to some data sent using
HTTP protocol, so to use this var the client (the browser) need to send data to the server.
Here's an example that will get the selected value using jquery. You should then update the div where you want the value to appear, but since it's not in your question I can't help!
dropDownIdis the id that you need to give to your dropDownList (in the CHtml::dropDownList html options)
You can also use an Ajax request. Its even better if you want to make some dependent dropdown lists. For example:
Then in your controller you can use POST Example: