I have this dropdown list, when I select the item from it the ajax post the item number
to the controller. I don't want the integer number, I actually want the name of the
selected item. So how can I perform something like that ?
here is my code :
echo $form->dropDownList($model,'user_country',$countryList,
array(
'ajax' => array(
'type' => 'POST',
'url' => CController::createUrl('signup/dynamicstates'),
'update' => '#User_user_region'
)
));
I want the post method sends the select country name in the list "USA" instead of 0 or 1 or any digit.
Page 1 of 1
Passing Selected Item In Dropdown To Controller Using Ajax, Htmloption, How ?
#2
Posted 13 January 2013 - 05:43 PM
How is $countryList being built? If you want a text value, it's simplest just to build it there.
For example, you could actually reference back a function from your model to dynamically get the list, such as replacing $countryList with
then in your model:
note the 'country','country' instead of a typical 'id','country' so it's using the text label as both the value and the label.
For example, you could actually reference back a function from your model to dynamically get the list, such as replacing $countryList with
echo $form->dropDownList($model,'user_country',$model->Countries,
array(
'ajax' => array(
'type' => 'POST',
'url' => CController::createUrl('signup/dynamicstates'),
'update' => '#User_user_region'
)
));then in your model:
public function getCountries() {
return CHtml::listData(Country::model()->findAllByAttributes(array('active'=>1),array('order'=>'sort_order,country')), 'country', 'country');
}note the 'country','country' instead of a typical 'id','country' so it's using the text label as both the value and the label.
Share this topic:
Page 1 of 1

Help












