How to get Form API #states selected value onchange? When I'm using #states to set the visibility of a form field I'm checking an input element for its value. Is there then any way to grab the selected value the moment it's selected?

In the working sample below I'm displaying some markup when a select list's value != '_none'. It works good so far. But how do I get the markup to display the value I selected?

Background is: it's a node reference select list and I'm trying to maybe load some fields from the selected node as preview inside the markup. The moment I'm writing this I think it's a stupid idea. I'm in Ajax with #states, right? And there might be no way to call node_load() or anything the like, right?

/**
 * Implements hook_form_alter().
 */
function MY_MODULE_form_alter(&amp;$form, &amp;$form_state, $form_id) {

  if ($form_id == 'MY_FORM') {

    $form['my_container'] = [
      '#type'   =&gt; 'container',
      '#states' =&gt; [
        'visible' =&gt; [
          ':input[name="my_field_name[und]"]' =&gt; ['!value' =&gt; '_none'],
        ],
      ],
    ];

    $form['my_container']['markup'] = [
      '#type'   =&gt; 'markup',
      '#markup' =&gt; /* selected value here */ ,
    ];
  }
}
Drupal #states is nothing more than the page containing JS data, and states.js reading them and adding necessary JS events to hide/show/etc fields. At the moment, there is no #states based method to get the selected value. 

Note that it's perfectly OK to add #states to elements that are passed through Ajax. The beauty is that, whenever something containing #states is rendered, Drupal pipes these JS data along with the Ajax response. Since behaviours are run everytime after an Ajax response, states.js can update its visibility rules even for Ajax-changed elements. 

I think your solution would be to use #ajax to do this. Your [#ajax]['callback'] will contain just-selected values in $form_state['input'], so you can use them.