I have a similar problem, but using ajax, and not knowing javascript.
_form
$form = $this->beginWidget('CActiveForm', array(
'id' => 'lifecare-form',
'enableAjaxValidation' => true,
'clientOptions' => array('validateOnSubmit' => true, 'validateOnChange' => true),
'focus' => array($model, 'product_code'),
));
Then an Ajax dropdown onchange
<?php
echo $form->dropDownList($model, 'debit_payment_method_id', CHtml::listData(PaymentMethod::model()->findAll(), 'payment_method_id', 'payment_method_name')
, array('ajax' => array(
'type' => 'POST',
'url' => CController::createUrl('lifecare/HideStopORDebitOrder'),
'update' => '#debitOrderDetails' ,
'data' => array('debit_payment_method_id' => 'js:this.value')
)));
?>
<?php echo $form->error($model, 'debit_payment_method_id'); ?>
And a div debitOrderDetails with many fields:
<div id="debitOrderDetails" class="row">
<fieldset>
<legend>Payment Details (Debit Order)</legend>
<div class="column">
<?php echo $form->labelEx($model, 'debit_AccountHolderTitle'); ?>
<?php echo $form->dropDownList($model, 'debit_AccountHolderTitle', CHtml::listData(Title::model()->findAll(), 'title_id', 'title_name'), array('empty' => '----')); ?>
<?php echo $form->error($model, 'debit_AccountHolderTitle'); ?>
</div>
<div class="column">
<?php echo $form->labelEx($model, 'debit_AccountHolderFirstName'); ?>
<?php echo $form->textField($model, 'debit_AccountHolderFirstName', array('size' => 30, 'maxlength' => 30)); ?>
<?php echo $form->error($model, 'debit_AccountHolderFirstName'); ?>
</div>
</fieldset>
</div>
Problem is, I have a method in the controller, but do not know how to toggle the
class="row hide" on the debitOrderDetails div
I have also set the access rules for actionHideStopORDebitOrder,
if I dont hide the row in the div, the ajax prints the echo from the controller, so I know the ajax call works.
What do I put in the controller method and update call in the ajax to hide the debitOrderDetails div?
All I want to do is if in the dropdown "Debit Order" is selected,
the debit order div must display, and if "Stop Order" is selected,
the stop order fields must be displayed.
controller
public function actionHideStopORDebitOrder() {
echo "row hide";
Yii::app()->end();
}
Any help will be much appreciated, I have spent hours and read almost the whole internet… 