Yii Framework Forum: Hiding/showing Form Element On Option Select - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Hiding/showing Form Element On Option Select Rate Topic: -----

#1 User is offline   conviera 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 2
  • Joined: 19-November 12

Posted 19 November 2012 - 10:02 AM

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
0

#2 User is offline   AndreiCurelaru 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 39
  • Joined: 11-November 12
  • Location:France

Posted 22 November 2012 - 03:59 AM

Hi,

Have you tried a jQuery piece like "onChange" on your select css #id ? ... or a simple "toogle".
Les Tags pour organiser le Forum FrenchYii : LINK
@AndreiCurelaru
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users