edk
(Edwardkoo)
July 11, 2012, 6:53am
1
In my view i have these
<div class="row">
<?php echo $form->labelEx($model,'His Name'); ?>
<?php echo $form->textField($model,'Name'); ?>
<?php echo $form->error($model,'Name'); ?>
</div>
Then i have a dropdownlist that allow user to select Male/Female. When user select Female i need the labelEx above to change to ‘Her Name’.
How should i do that? (without refreshing the page)
use ajax on select of dropdown…
<?php echo CHtml::dropDownList('country','',array(),array('prompt'=>'Select',
'ajax' => array(
'type'=>'POST',
'url'=>CController::createUrl('registration/region'), //create an action and echo his/her
'update'=>'#region_id', //id to refresh, his/her
'data'=>'js:$(this).serialize()',
))); ?>
edk
(Edwardkoo)
July 11, 2012, 8:28am
4
Hi Rajith
How do i get ‘#region_id ’ from <?php echo $form->labelEx($model,‘His Name’); ?>
Also for my action in controller how do i check the value of selected sex and then echo accordingly?
public function actionChangeSex()
{
echo "Her";
}
Hi Rajith
How do i get ‘#region_id ’ from <?php echo $form->labelEx($model,‘His Name’); ?>
Also for my action in controller how do i check the value of selected sex and then echo accordingly?
public function actionChangeSex()
{
echo "Her";
}
give that id to a div or to that label
the value selected will get as $_POST[ur model name] in the controller.
edk
(Edwardkoo)
July 12, 2012, 8:09am
6
Hmm… my action doesn’t get call at all
echo $form->dropDownList($model, 'Sex', $SexArray,
array(
'ajax' => array(
'type'=>'POST',
'url'=>CController::createUrl('Person/ChangeSex'),
'update'=>'#Person_Name',
'data'=>'js:$(this).serialize()',
)));
I manually call ChangeSex at browser and it display correct value. The dropdownlist doensn’t call the ajax post somehow…
use firebug- console in firefox…u can see the post error… check it… or controller path issue.
genn
(Ch Velkov)
July 12, 2012, 3:08pm
8
Ajax… for this?
Come on … its like trying to kill an insect with an anti-aircraft missile - it would work, but the question is would it be worth it .
In this case - no.
Ajax is necessary only when updating with dynamic content, which is not available to the client. In this case you already know the content:
http://jsbin.com/otokob
about 4 lines of JS code
edk
(Edwardkoo)
July 17, 2012, 2:34am
9
genn:
Ajax… for this?
Come on … its like trying to kill an insect with an anti-aircraft missile - it would work, but the question is would it be worth it .
In this case - no.
Ajax is necessary only when updating with dynamic content, which is not available to the client. In this case you already know the content:
http://jsbin.com/otokob
about 4 lines of JS code
I agree this is how it should be done but i am still trying to figure out how to incorporate this into yii, finding the right place to insert the script and etc.
Thank you all for the advices.