Basically, I want to know how I can copy the original value of a drop-down list to a hidden drop-down menu.
Since I currently have a radio volume that disables a specific dropdown value, but the value will not be sent to PHP. Therefore, I added the original drop-down list to the hidden field with the same name , but when it is turned on again, the field does not copy its value.
this is what i have:
<div class="row">
<?php echo $form->labelEx($model,'clientPackagedService_id'); ?>
<?php $client = Client::model()->findByPk(1);?>
<?php echo $form->dropDownList($model, 'clientPackagedService_id', CHtml::listData($client->clientPackagedservices(array('condition'=>'client_id='.$client->id.' AND booking_id IS NULL')),'id','packagedServiceInfo')
,array(
'disabled'=>'disabled',
'prompt'=>'Select Packaged Service....',
'ajax' => array( 'type'=>'POST',
'url'=>CController::createUrl('updateMasseuseAndStationListPSID'),
'data'=>array('clientPackagedService_id'=>'js:this.value', 'dt'=>'js:$("#Booking_date").val()', 'timeStart'=>'js:$("#Booking_timeStart").val()'),
'dataType'=>'json',
'success'=>'js:function(data) {
var mass="#'.CHtml::activeId($model, 'masseuse_id').'";
$(mass).html(data.masseuse);
$(mass).trigger("chosen:updated");
$(mass+"_chzn").css("width","300px");
$(mass+"_chzn > .chzn-drop").css("width","298px");
var station="#'.CHtml::activeId($model, 'station_id').'";
$(station).html(data.station);
$(station).trigger("chosen:updated");
$(station+"_chzn").css("width","300px");
$(station+"_chzn > .chzn-drop").css("width","298px");
//alert(data.timeEnd);
var timeEnd="#'.CHtml::activeId($model, 'timeEnd').'";
$(timeEnd).val(data.timeEnd);
}',
)
)
); ?>
<?php echo $form->error($model,'clientPackagedService_id'); ?>
</div>
<div>
<?php echo $form->hiddenField($model, 'clientPackagedService_id'); ?>
</div>
this is my javascript
$(document).ready(function(){
$('input[type=radio]').change(function(){
if(this.value == '0'){
$("#Booking_clientPackagedService_id").prop("disabled", false);
$("#Booking_service_id").prop("disabled", true);
$("#Booking_service_id").val('0');
}
else if(this.value == '1'){
$("#Booking_service_id").prop("disabled", false);
$("#Booking_clientPackagedService_id").prop("disabled", true);
$("#Booking_clientPackagedService_id").val('0');
}
});
})
Am I providing hiddenField with the same name as the original, or shouldn't I? If so, how can I copy the value of the original dropdown to hiddenField when it is turned back on?