[Solved] Textbox Enabled/disabled Status Based On Dropdownlist Value

I have a dropdownlist and a textbox in my form. I want the textbox to be enabled only when an option is selected in the dropdownlist i.e. it is not at the empty value.

	<div class="row">

		<?php echo $form->labelEx($model,'username'); ?> 

		<?php echo $form->textField($model,'username',array('size'=>20,'maxlength'=>20, 

                                       'disabled'=>(dropdownlist value not empty)); ?> // select.value != ""

		<?php echo $form->error($model,'username'); ?>


Kindly help me out with this.

If there is no value selected in the dropdown list, the textbox should be disabled. If user changes its value, the textbox should be enabled. By default, it is disabled. I have managed to detect the change event of select box using the following script.

<?php       Yii::app()->clientScript->registerScript('myselectbox', "$('#myselectbox').change(function(){ alert('changed'); });"); ?>

How do i access the textbox with id ‘username’? Like if

(document.getElementById("myselectbox").value !== "") {

                document.getElementById("username").disabled = true;


                else {

                document.getElementById("username").disabled = false;

How to access its enabled/disabled property?

Viewed the source in Firebug and the id assigned to username was Account_username.

<?php      Yii::app()->clientScript->registerScript('myselectbox', "$('#myselectbox').change(function(){ Account_username.disabled=false; });"); ?>