How to change autocomplete_route_parameters value on change of select option? How to change autocomplete_route_parameters value on change of select option?

I have a form element and inside autocomplete_route_parameters, I want to change $langcode value when I select any language from select list.

$form['node_items'] = array(
            '#type' =&gt; 'textfield',
            '#autocomplete_route_name' =&gt; 'autocomplete_node_search.autocomplete',
            '#autocomplete_route_parameters' =&gt; array('skip_node_id_string' =&gt; $skip_node_id_string, 'langcode' =&gt; $langcode),

          );


So if I choose language french from select list, $langcode should become = 'fr' via ajax.
I have used below example to do that.

https://api.drupal.org/api/examples/ajax_example%21ajax_example.module/function/ajax_example_dependent_dropdown/7.x-1.x

Customized it as listed below.

$form_state_values = $form_state-&gt;getValues();
if (!empty($form_state_values['language'])) {
  // write your logic here to prepare $skip_node_id_string &amp; $langcode
}
$form['first'] = [
 '#type' =&gt; 'textfield',
 '#title' =&gt; $this-&gt;t('first'),
 '#autocomplete_route_name' =&gt; 'autocomplete_node_search.autocomplete',
 '#autocomplete_route_parameters' =&gt; 
 array('skip_node_id_string' =&gt;$skip_node_id_string, 
 'langcode' =&gt; $langcode),
 '#prefix' =&gt; '&lt;div id="change-lang-wrap"&gt;',
 '#suffix' =&gt; '&lt;/div&gt;',
];
$form['language'] = [
 '#type' =&gt; 'select',
 '#title' =&gt; $this-&gt;t('language'),
 '#options' =&gt; ['someval'],
 '#ajax' =&gt; [
  'callback' =&gt; [$this, 'changeLanguage'],
  'event' =&gt; 'change',
  'wrapper' =&gt; 'change-lang-wrap',
 ],
];
// Ajax callback.
public function changeLanguage(array &amp;$form, FormStateInterface $form_state) {
 return $form['first'];
}


Hope this will fix your issue.

Tried below links, but no luck.

https://www.drupal.org/node/1135288