How to add a label description for an EditText field

Hello guys,

How are you doing?

I have researched for many hours before to create this topic because I didn’t find what I am looking for. :wacko:

Let’s suppose I have these table in my database:


|id |   color | action |     image    |


|1  | yellow  |   PP   | profile_pic  |

|2  | blue    |   PRP  | product_pic  |

|3  | green   |   GP   | gallery_pic  |

|4  | red     |   FP   | forum_pic    |


On my form I have something like that:


[  EditText       ]

What's your color?

[dropdown_list_name]    [ Label ] 

I would like when I select a color in dropdown list, on the next field (the side) display the action of the color in according to the table:

I have done the dropdown list for the color names (it’s working very well), I need only to put the Label field to display the Action name (same as in the table):

Take a look on the samples below:



[  Tárcio          ]

What's your color?

[YELLOW            ]    [ PRP ]


[BLUE              ]    [ PP ]

I would appreciate your help in order to solve my issue. ;D

Thank you!


Tárcio Sales


Skype: starcio3030

If I understood U right, all U need is to connect label value to select box U already made, so U could handle on change event from select.

Suggestion, when creating data to populate select also collect action from DB table, I would place it into data in option, than all U need to do is attach on change event to select, where U will on change get data-action from selected option and place it where ever U need on page.

Hope this can help U

1 Like

Hello dragan.zivkovic

Thank you for you reply.

I think I got it your idea. But I don’t know how to implement this.


|cod_departamento  | descricao_departamento |  supervisor   |  


|       1          |     HR                 |   Tony        |

|       2          |     Purchase Dept      |   Kevin       |

Below is my current code, from 3rd to 6th line is relating to the dropdown, then next to this field I would like to add the Label field.

1: <div class="row">

2: <?php echo $form->labelEx($model,'cod_departamento'); ?>

3: <?php echo $form->dropDownList($model,'cod_departamento',

4:     CHtml::listData(Departamentos::model()->findAll(),

5:     'cod_departamento','desc_departamento'),

6:     array('empty'=>'Selecione... '));?>

7: <?php echo CHtml::textField('Text',$model->cod_departamento, 

8:    array('id'=>'cod_departamento','width'=>100,'maxlength'=>100)); ?>

9: <?php echo $form->error($model,'cod_departamento',array('style' =>'color: red')); ?>


Could you give me more information please ?

Thanks in advance



You will need to use either JQuery or JQuery (Ajax) or both.

Hello James,

you’re right.

I am researching on the internet for some example using Ajax or JQuery as you said.

However I didn’t find anything about it yet. :(

if you have any example please let me know.




Could someone help me please? ???

I doubt someone will help you with this as it quite painful to have to explain the process to get this work.

You need to attach an event handler to your drop down to fire off an ajax request to a PHP controller action on your server.

The controller action will return the data you want to display next to the dropdown.

After the data has been returned you will need to update the segment of html with the data using JQuery.


	type: "GET",

	cache: false,


	success: function(response) {




Basically the #ID-OF-UPDATEABLE-HTML-ELEMENT is the html element that will update with the data from your server.

URL-TO-CONTROLLER-ACTION is the action that will process the request and send back the data.

You will need to put this ajax method inside an onchange event handler attached to the dropdown, and you will need to get the dropdowns value and pass it to the request in the params of the URL etc.

If you give me your Skype I could help you with this.

hey James,

I would appreciate your help.

my skype is starcio3030.

Many thanks.


Ok added you to Skype.

Message me when you are online.

Many Thanks JamesBarnsley for your help. ::)

It works perfectly!

Thank you!


Glad its working.