how to add #states property to a field element in drupal 7? I wanted to add #states property to a select list field in cck input form created by content type. I ve tried the following code but the states property is not set to the field. Can anyone suggest on how to do it.

$form['field_ctype']['und']['#ajax']=array('callback' =&gt;'_ajax_menu_check_boxes',
                                              'wrapper' =&gt;'edit-field-sub-menu',
                                            'effect' =&gt; 'fade',
                                            'event' =&gt; 'change',
                                            );
$form['field_sub_menu']['und']['#states']=array(
                                  'visible' =&gt; array(
                                 ':input[name="field_ctype"]' =&gt; array('value' =&gt; '2')));


could anyone suggest me where I am going wrong. Is it possible to add ajax property ans states property to a same field?

Note : The Ajax property for the field_ctype works fine. Only the states property is not working.
Fields always have have nested names like field_something[und][value] or something like that. I guess your query (:input[name="field_ctype"]) is wrong.

I find the easiest way to get it right is using the Firebug/Developer tools Console. Play around with jQuery(':input[...]') until it matches what you're expecting. Also check the name of the form element.