Enthu
(Zackrocha14)
June 17, 2016, 6:21am
1
I am currently facing a problem on saving values from a dropdownlist. As you can see, I have an option in the dropdownlist that will show a textfield upon user selection. This option is working well and saving to database.
I am currently unable to save the remaining option.(Such as "Car" or "Bike"). Anyone can enlighten me on this?
<div class="row">
<?php echo $form->labelEx($model,'transport_allowance'); ?>
<?php echo $form->dropDownList($model,'transport_allowance',array('450'=>"Car",'200'=>"Bike","Others"=>"Others"),array('onchange'=>'return muFun(this.value)')); ?>
<?php echo $form->error($model,'transport_allowance'); ?>
</div>
<div id="TLID_DIV" style="display:none">
<div class="row">
<?php echo $form->labelEx($model,'transport_allowance'); ?>
<?php echo $form->textField($model,'transport_allowance'); ?>
<?php echo $form->error($model,'transport_allowance'); ?>
</div>
</div>
<script>
function muFun(obj){
if(obj=="Others"){
document.getElementById('TLID_DIV').style.display="block";
return false;
}else{
document.getElementById('TLID_DIV').style.display="none";
return false;
}
}
</script>
Thank you for any help rendered.
patrickm
(Yiiframework)
June 17, 2016, 10:22am
2
What is being posted to the server when you are unable to save?
Enthu
(Zackrocha14)
June 20, 2016, 1:43am
3
It does not capture both the other two data. Value will remain and update from the textfield only.
I have tried the following codes below but the latter is not saving too. Any ideas?
<div class="row">
<?php echo $form->labelEx($model,'transport_allowance'); ?>
<?php echo $form->dropDownList($model,'transport_allowance',array('Car'=>'Car','Others'=>'Others'),array('onchange'=>'return muFun(this.value)')); ?>
<?php echo $form->error($model,'transport_allowance'); ?>
</div>
<div id="others" style="display:none">
<div class="row">
<?php echo $form->labelEx($model,'transport_allowance'); ?>
<?php echo $form->textField($model,'transport_allowance'); ?>
<?php echo $form->error($model,'transport_allowance'); ?>
</div>
</div>
<div id="car" style="display:none">
<div class="row">
<?php echo $form->hiddenField($model,'transport_allowance',array('value'=>'450')); ?>
</div>
</div>
<script>
function muFun(obj){
if(obj=="Car"){
document.getElementById('car').style.display="block";
document.getElementById('others').style.display="none";
}else if(obj=="Others"){
document.getElementById('others').style.display="block";
document.getElementById('car').style.display="none";
}
}
</script>
Enthu
(Zackrocha14)
June 21, 2016, 4:31am
4
Enthu:
It does not capture both the other two data. Value will remain and update from the textfield only.
I have tried the following codes below but the latter is not saving too. Any ideas?
<div class="row">
<?php echo $form->labelEx($model,'transport_allowance'); ?>
<?php echo $form->dropDownList($model,'transport_allowance',array('Car'=>'Car','Others'=>'Others'),array('onchange'=>'return muFun(this.value)')); ?>
<?php echo $form->error($model,'transport_allowance'); ?>
</div>
<div id="others" style="display:none">
<div class="row">
<?php echo $form->labelEx($model,'transport_allowance'); ?>
<?php echo $form->textField($model,'transport_allowance'); ?>
<?php echo $form->error($model,'transport_allowance'); ?>
</div>
</div>
<div id="car" style="display:none">
<div class="row">
<?php echo $form->hiddenField($model,'transport_allowance',array('value'=>'450')); ?>
</div>
</div>
<script>
function muFun(obj){
if(obj=="Car"){
document.getElementById('car').style.display="block";
document.getElementById('others').style.display="none";
}else if(obj=="Others"){
document.getElementById('others').style.display="block";
document.getElementById('car').style.display="none";
}
}
</script>
Managed to create a workaround by adding another field and inserting separately.