How To Hide/show Textfield In Active Form?

Hi all,

  Currently i have one form in which i want to hide the text fields based on the selection from dropdownlist.

I have tried to resolve this problem but don’t get any output from it.

I have tried following code in my form:

$(function(){

         if($("#DropDownTextFiledName").Val() == 2)


             {


                $("TextFieldName").hide();


             }

});

And i have declared 1=show & 2=hide.

Use .change() trigger:




$( "#DropDownTextFiledName" ).change(function() {

  if($( this ).val() == 2){

	$("TextFieldName").hide();

  } else {

	$("TextFieldName").show();

  }

});

Thanks for the reply…

I have put this code in

<script>

</Script>

at the start of the form but it doesn’t works.

Can u plz send me any sample code of such type of form?

Thanks for the reply…

I have put this code in

<script>

</Script>

at the start of the form but it doesn’t works.

Can u plz send me any sample code of such type of form?

Check this http://jsfiddle.net/ycKzP/

The script needs to occur after the element has been rendered, or you could wrap it inside jquery’s ready function. You could also use something like this at the top of your view file:




Yii::app()->clientScript->registerScript('any_unique_id', "

$( "#DropDownTextFiledName" ).change(function() {

  if($( this ).val() == 2){

        $("TextFieldName").hide();

  } else {

        $("TextFieldName").show();

  }

});

");