I use [size="3"]display element on dropdown selection [/size] ,
I want to display another dropdown on selection of first one and I use following code .
step : 1 => code for view file
<div class="row"> // first dropdown for selection
<?php echo $form->labelEx($model,'E_ROLE'); ?>
<?php echo $form->dropDownList($model,'E_ROLE',array(""=>"Select","Admin"=>"Admin","Employee"=>"Employee","TL"=>"TL"),array('onchange'=>'return muFun(this.value)')); ?>
<?php echo $form->error($model,'E_ROLE'); ?>
</div>
<div id="TLID_DIV" style="display:none"> // hidden dropdown enable on selection first one
<div class="row">
<?php echo $form->labelEx($model,'E_TLID'); ?>
<?php echo CHtml::activeDropDownList($model,'E_TLID', $model->getTL() , array('prompt'=>'Select') ); ?>
<?php echo $form->error($model,'E_TLID'); ?>
</div>
</div>
step : 2 => code for js
function muFun(obj){
if(obj=="Employee"){
document.getElementById('TLID_DIV').style.display="block";
return false;
}else{
document.getElementById('TLID_DIV').style.display="none";
return false;
}
}
[size="3"][u][b]It works 100%
If helpful give user rating to my profile.[/b][/u][/size]
Hi All,
I am a newbie to yii and trying to hide and show form elements based on selection of an option from another field.
My form has a dropDownList with "-/Low/High " and I want to display a low field if low is selected, or a high field if high is selected.
This is my form
<td id="riskDropDownList">
<?php echo $form->labelEx($model,‘patient_risk’); ?>
<?php echo ZHtml::enumDropDownList($model,‘patient_risk’,array(‘style’=>‘width:262px;’,)); ?>
<?php echo $form->error($model,‘patient_risk’); ?>
</td>
<td class="lowRiskField">
<?php echo $form->labelEx($model,‘if_risk_low_risk_factor’); ?>
<?php echo $form->dropDownList($model,‘if_risk_low_risk_factor’, $model->riskFactorArray()); ?>
<?php echo $form->error($model,‘if_risk_low_risk_factor’); ?>
</td>
<td class="highRiskField">
<?php echo $form->labelEx($model,‘if_risk_high_risk_factor’); ?>
<?php echo $form->dropDownList($model,‘if_risk_high_risk_factor’,$model->riskFactorArray()); ?>
<?php echo $form->error($model,‘if_risk_high_risk_factor’); ?>
</td>
and this is my JQuery script
<script type="text/javascript">
$(document).ready(function(){
$("#riskDropDownList ").change(function() {
if ($("#riskDropDownList ").val() == ‘Low’)
{
$(".lowRiskField").show();
}
else if ($("#riskDropDownList ").val() == ‘High’)
{
$(".highRiskField").show();
}
else
{
$(".lowRiskField").hide();
$(".highRiskField").hide();
}
});
$("#riskDropDownList ").change();
});
</script>
Many thanks for your help in advance