How can I add an AJAX callback to a checkbox? I am using taxonomy manager module I want to add ajax callback to checkbox tree view for checkbox is checked condition but it is not working can some one please suggest me. I have modified the code like this
$form[$term-&gt;tid]['checkbox'] = array(
      '#type' =&gt; ($multiple) ? 'checkbox' : 'radio',
      '#title' =&gt; $term-&gt;name, // Escaping is done in theme wrappers.
      '#value' =&gt; $value,
      '#return_value' =&gt; $term-&gt;tid,
      '#ajax' =&gt; array(
        'callback' =&gt; 'ajax_example_autocheckboxes_callback',
        'wrapper' =&gt; 'checkboxes-div',
        'method' =&gt; 'replace',
        'effect' =&gt; 'fade',
      ),
      '#required' =&gt; FALSE,
      '#theme_wrappers' =&gt; ($multiple) ? array('taxonomy_manager_tree_checkbox') : array('taxonomy_manager_tree_radio'),
      '#highlight' =&gt; in_array($term-&gt;tid, $terms_to_highlight) ? TRUE : FALSE,
    );

This is the taxonomy manager module theme function.
function theme_taxonomy_manager_tree_checkbox($variables) {
  global $user;
  $element = $variables['element'];
  $element['#attributes']['type'] = 'checkbox';
  $element['#attributes']['ajax']['event'] = 'change';
  element_set_attributes($element, array('id', 'name', '#return_value' =&gt; 'value'));

  // Unchecked checkbox has #value of integer 0.
  if (!empty($element['#checked'])) {
    $element['#attributes']['checked'] = 'checked';
  }
  _form_set_class($element, array('form-checkbox'));
  $output = '&lt;input' . drupal_attributes($element['#attributes']) . ' /&gt;';
  /* custom alter function */
  if(user_is_logged_in()){
    if(!user_access('administer taxonomy')){
      $cdms_taxonomy_id = taxonomy_term_load($element['#return_value']); 
      // echo &quot;IF&quot;; exit;     
    }else{
      $cdms_taxonomy_id = taxonomy_term_load($element['#return_value']);
      // echo &quot;Else&quot;; exit;      
    }
  }
  // echo '&lt;pre&gt;';print_r($variables);  echo&quot;Term load&quot;; print_r($cdms_taxonomy_id);  exit;
  $data = [
    'title' =&gt;  $element['#title'],
    'tid' =&gt; @$cdms_taxonomy_id-&gt;field_cdms_txy_id[LANGUAGE_NONE][0][value],
    'count' =&gt; '',
  ];
  // Calling all modules implementing hook_my_data_alter():
  drupal_alter('my_data', $data);
  
  if (!in_array(&quot;Client User&quot;, array_values($user-&gt;roles))) {
  $title = $element['#title'] .&quot;(&quot;.$data['count'].&quot;)&quot;;
}else{
   $title = $element['#title'];
}
  if (in_array(&quot;Client User&quot;, array_values($user-&gt;roles))) {
    $title = check_plain($title);
  }else{
    if (isset($element['#link'])) {
        $attr = array();
        $attr[&quot;class&quot;][] = &quot;term-data-link&quot;;
        $attr[&quot;class&quot;][] = &quot;term-data-link-id-&quot; . $element['#return_value'];
        if (isset($element['#extra_info'])) {
          $attr[&quot;title&quot;] = $element['#extra_info'];
        }
        $title = l($title, $element['#link'], array('attributes' =&gt; $attr));
      }
      else {
        $title = check_plain($title);
      }
  }
  
  $element['#children'] = '&lt;label class=&quot;option&quot;&gt;' . $output . ' ' . $title . '&lt;/label&gt;';
  $element['#title_display'] = 'none';
  return theme('form_element', array('element' =&gt; $element));
}
ajax_example_autocheckboxes_callback function is not defined in the above code.

Also please update more info about what you are trying to do.

$form[$term-&gt;tid] = array(... 'ajax_example_autocheckboxes_callback' ...); //ajax callback
$form['tree']; //new field.


after the above function call you can get new built_info of $form_state as its rebuilt. So you can alter output of the field.

function ajax_example_autocheckboxes_callback($form, $form_state) {
  dsm($form_state);
  return $form['tree']; // this is a new field.
}


I will update my answer if more information is provided.