How to create a select drop down that opens a URL? I have a select drop down. When the user selects a value from the drop down, the user will then click on a button and based on what the user has selected it will open a url in a new tab. While this is quite simple in JavaScript I am struggling how to figure this out in drupal.

So far I have created a custom module which has a select form and the submit button. From here I am stuck as to how to write if user has selected value a open google.com etc. any suggestions or pointers would be greatly appreciated.
You can do this by using $form_state-&gt;setResponse() together with TrustedRedirectResponse.

Create the dropdown, like this:

$form['select'] = [
  '#type' = 'select',
  '#title' =&gt; t('Select'),
  '#options' = [
    'https://google.com' =&gt; t('Google'),
    // More links...
  ]
];


To open the link in a new tab, you can add this to your form:

$form['#attributes' =&gt; ['target' =&gt; '_blank']];


Then create the submit handler, like this:

public function submitForm(array &amp;$form, FormStateInterface $form_state) {
  $form_state-&gt;setResponse(new TrustedRedirectResponse($form_state-&gt;getValue('select'), 302));
  // You can change the response code from 302 to whatever you need
}