Ajax on select show data markup on select basic ajax
//ref : https://www.deckfifty.com/blog/2012-09/drupal-form-api-using-ajax
/**
* Implements hook_menu().
*/
function deckfifty_menu() {
$items['example'] = array(
'title' => 'Example Page',
'page callback' => 'drupal_get_form',
'page arguments' => array('deckfifty_example_form'),
'access arguments' => array('access content'),
);
return $items;
}
function deckfifty_example_form($form, &$form_state) {
$form['fox_color'] = array(
'#title' => t('Specify the color of the fox:'),
'#type' => 'select',
'#options' => drupal_map_assoc(array('', 'brown', 'black', 'white')),
'#ajax' => array(
'callback' => 'deckfifty_fox_ajax_callback',
'wrapper' => 'deckfifty_fox_ajax_wrapper',
),
);
$form['fox_wrapper'] = array(
'#type' => 'markup',
'#prefix' => '<div id="deckfifty_fox_ajax_wrapper">',
'#suffix' => '</div>',
);
if( (isset($form_state['values']['fox_color'])) && ($form_state['values']['fox_color'] != '') ) {
$form['fox_wrapper']['#markup'] = t('The quick @color fox jumps over the lazy dog.', array('@color' => $form_state['values']['fox_color']));
}
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Save'),
);
return $form;
}
function deckfifty_fox_ajax_callback($form, $form_state) {
return $form['fox_wrapper'];
}