Hiding dropDownList

Dear All,

From action, based on the parameter values I receive in view , I want to hide or show the drop down box . Could some one suggest me what is the html option I can use in dropdownbox for this?

action code


$this->render('myCars', array('place_type' =>$place_type));

in the above code $place_type is true or false … If it is true hide the dropdown list in view other wise show it in view.


<?php

echo CHtml::dropDownList('car', '', array("prompt"=>" - Select Car- "), array());

?> 

Looks some thing simple , but not finding the right option

Thanks

Regards

Yii Fan


<?php

    if(!$place_type) {

        echo CHtml::dropDownList('car', '', array("prompt"=>" - Select Car- "), array());

    }

?>

Thanks outrage for your response . But my case the dropdownlist should be there and it should be hidden . Because there is a Jquery script in this view that makes dropdownlist visible for some user actions .


<?php

    if(!$place_type) {

        echo CHtml::dropDownList('car', '', array("prompt"=>" - Select Car- "), array());

    }

?>

For the above code dropdownlist won’t even exists if it is true.

Thank You

Regards

Yii Fan

In that case you need to use Javascript to hide the div on page load.

Something like:


<script>

    if("<?php echo $place_type; ?>" == "true") {

        ...hide the div (change class with jquery maybe);

    }

</script>

Very simple example but I’m sure you can figure it out :) Obviously the javascript will have to be called after the control has rendered otherwise it won’t exist.

You might be looking for this method though after re-reading your post:

http://www.yiiframework.com/forum/index.php/topic/25572-add-css-class-on-select-box/

Thank You Outrage for your help . I found the solution and here it


<?php

    if(!$place_type) {

        echo CHtml::dropDownList('car', '', array("prompt"=>" - Select Car- "), array('place_type' =>$place_type));

    }

?>

and in the script


 $cs->registerScript(

            'myScript',

           ' if ($("#village").attr("place_type")){$("#village").hide();}',

            CClientScript::POS_END

    );

Basically adding a attribute to dropdownlist and in the script … hiding it based on the attribute value .Also using CClientScript::POS_END

THANKS A LOT FOR YOUR HELP

Regards

Yii Fan