javascript on select element only works for anonymous users

Created on 12 October 2023, about 1 year ago

Problem/Motivation

Accessing a select element with javascript only works when a user is not logged in. Other element types don't have this issue. The select in question is a taxonomy term entity. It doesn't matter if I add js to the CSS/JS section of the form or through normally attached JS. I can see the selectors in the source code. Testing in Incognito works as expected. When logged in, the selector is never accessed. Am I missing something?

markup:

<select class="webform-entity-select form-select" data-drupal-selector="edit-names" id="edit-names" name="names">
	<option value="" selected="selected">- None -</option>
	<option value="141">Sally</option>
	<option value="146">Fred</option>
	<option value="151">Karan</option>
</select>

js:

var jsName = 'Fred';
var dd = document.getElementById('edit-names');
for (var i = 0; i < dd.options.length; i++) {
    if (dd.options[i].text === jsName) {
        dd.selectedIndex = i;
        break;
    }
}

console error:
Uncaught TypeError: Cannot read properties of null (reading 'options')

πŸ’¬ Support request
Status

Closed: outdated

Version

6.1

Component

Code

Created by

Live updates comments and jobs are added and updated live.
  • JavaScript

    Affects the content, performance, or handling of Javascript.

Sign in to follow issues

Comments & Activities

  • Issue created by @cobasa
  • Status changed to Closed: outdated about 1 year ago
  • πŸ‡ΊπŸ‡ΈUnited States jrockowitz Brooklyn, NY

    This ticket feels more like a support request which should be handler in other channels

Production build 0.71.5 2024