Dynamic select list in the form API (dependent dropdown list)? First I want to select State (like Tamil Nadu, Sikkim, Kerala) after selecting state, depended city list will be display another dropdown list ( for example Tamil Nadu -> Chennai, Salem, Karur and Kerala -> Trivandrum, Kochin etc)

Please help me please how to make it, here i have tried some coding but does not work, Please help me 

Sstate - Table

$query_state = db_select('state', 's');
$query_state-&gt;fields('s',array('State_code','State_name'));
$query_state-&gt;orderBy('State_name','ASC');
$state_results = $query_state-&gt;execute();
$options_state = array();

foreach($state_results as $state_record) {
  $options_state[$state_record-&gt;State_code]=t($state_record-&gt;State_name);
}

$form['state'] = array(
  '#type' =&gt; 'select',
  '#title' =&gt; t('State'),
  '#options' =&gt; $options_state,
  '#required' =&gt; TRUE,
);


City - Table 

$query_city=db_select('city', 'c');
$query_city-&gt;fields('c',array('District_Code','District_Name'));
$query_city-&gt;condition('State_Code','$state_record-&gt;State_code','=');
$query_city-&gt;orderBy('District_Name','ASC');
$city_results = $query_city-&gt;execute();
$options_city = array();

foreach($city_results as $city_record) {
  $options_city[$city_record-&gt;District_code]  =t($city_record-&gt;District_Name);
}

$form['city'] = array(
  '#type' =&gt; 'select',
  '#title' =&gt; t('District'),
  '#options' =&gt; $options_city,
  '#required' =&gt; TRUE,
  '#states' =&gt; array(
    'visible' =&gt; array(
      ':input[name="state"]' =&gt; array('value' =&gt; $options_state)
    )
  )
);
Basically, in your form declaration, you have to add

In your form['state'] :

'#ajax' =&gt; array(
  'callback' =&gt; '_ajaxfunction',
  'wrapper' =&gt; 'divaroundseconddropdown'
);


Then in your form['town'] :

'#prefix' =&gt; '&lt;div id="divaroundseconddropdown"&gt;',
'#suffix' =&gt; '&lt;/div&gt;',


Now in your _ajaxfunction :

function _ajaxfunction($form, $form_state) {
  return $form['city'];
}


Now, back to your form['town'], you simply have to build your $options with the $form_state['values']['state'] variable, which will contain what has been filled in the first dropdown.

Everything is documented here.

[EDIT]

First replace $state_record in your $query_city by $form_state['values']['state']; *You can check if the value is formatted the right by dpm($form_state); in your _ajaxfunction.

Then :

$form['state']= array(
  '#type' =&gt; 'select',
  '#title' =&gt; t('State'),
  '#options' =&gt;$options_state,
  '#required' =&gt; TRUE,
  '#ajax' =&gt; array(
    'callback' =&gt; '_ajaxfunction',
    'wrapper' =&gt; 'divaroundseconddropdown'
  ),
);


$form['city']= array(
  '#type' =&gt; 'select',
  '#title' =&gt; t('District'),
  '#options' =&gt; $options_city,
  '#prefix' =&gt; '&lt;div id="divaroundseconddropdown"&gt;',
  '#suffix' =&gt; '&lt;/div&gt;',
  '#required' =&gt; TRUE,
  '#states'=&gt;array(
    'visible'=&gt;array(
      ':input[name="state"]' =&gt; array(
        'value'=&gt;$options_state))));


Close your function, open a new one :

function _ajaxfunction($form, $form_state) { return $form['city']; }