Ajax textfield in hook_form_alter I'm attaching ajax on textfield value. One enter value in textfield and ajax callback returns form element. 

Below code is showing ajax 500 error. Can anyone tell what is mistake in this code?

function hook_form_alter(&amp;$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) {

    $form['field_base_price']['widget'][0]['value']['#ajax'] = array(
            'event' =&gt; 'change',
            'wrapper' =&gt; 'final-price-wrapper',
            'callback' =&gt; 'final_price_ajax_callback',
            'method' =&gt; 'replace',
          );

    $form['field_final_price']['#prefix'] = '&lt;div id="final-price-wrapper"&gt;';
        $form['field_final_price']['#suffix'] = '&lt;/div&gt;';
          $form['final_price_label'] = array(
            '#weight' =&gt; 11,
            '#prefix' =&gt; '&lt;div id="final-price-wrapper" class="field-name-field-final-price form-item"&gt;',
            '#suffix' =&gt; '&lt;/div&gt;',
          );
          $form['final_price_label']['title'] = array(
            '#type' =&gt; 'markup',
            '#markup' =&gt; '&lt;label&gt;' . $form['field_final_price']['widget'][0]['value']['#title'] . '&lt;/label&gt;',
          );

    }

    /**
     * Final price AJAX callback.
     */
    function final_price_ajax_callback($form, $form_state) {
      return $form['final_price_label'];
    }
You can use simple jQuery to achieve this then. Try putting the following code in your JS file: 

$("#fname").blur(function(){
  var fname = $("#fname").val();
$("#lname").val(fname);
});