Hi guys,
I have two dropdown list and one text box (Country state mobile-Country-code)
while i’m selecting the country from dropdown list it displays related states in the country,
i want to display both states and mobile country code
The states in the other table , but the mobile-country-code is in the same country table…
please help me…
my controller:
/**
* To load the states for the country
*/
public function actionGetStates() {
$country_id = $_REQUEST['region_id'];
foreach(Subregions::items($country_id) as $value => $name)
{
echo CHtml::tag('option',
array('value'=>$value),CHtml::encode($name),true);
}
}
form.php:
<td>Country *</td>
<td>
<?php echo $form->dropDownList($userModel, 'region_id', Regions::items(),
array( 'ajax' => array( 'type' => 'post',
'url' => $this->createUrl('users/getstates'),
'beforeSend' => 'function() { $("#Users_subregions_id").empty();
$("#Users_subregions_id").append("<option>Loading... </option>");
this.url = this.url + "®ion_id=" + $("#Users_region_id").val();}',
'update' => '#Users_subregions_id'),
'style' => 'width: 140px;'),
array('type'=>'POST', 'url'=>Users::createUrl('GetCountryCode'),
'success'=>'js:function(data{$("#country_code").val(data)}',
'data'=>array('country_id'=>'js:this.value'),),
array('onchange'=>"$('#country_code').val($(mcountrycode).text()"));
?>
</td>
<td>State *</td>
<td><?php $states = Subregions::items($userModel->region_id);
if (count($states) == 0) {
$states = array( '0' => 'Select country first');
}
echo $form->dropDownList($userModel, 'subregions_id', $states, array('style' => 'width: 140px;'));
?>
</td>
<td>Contact Number</td>
<td ><?php echo $form->textField($userModel, "mcountrycode"
// array('id'=>'country_code',
// 'name'=>'country_code')
)?></td>
please someone could give an idea how to update an textfield & dropdownlist based on a dropDownList value using ajax?