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