- Issue created by @cobasa
- Status changed to Closed: outdated
about 1 year ago 3:27pm 12 October 2023 - πΊπΈUnited States jrockowitz Brooklyn, NY
This ticket feels more like a support request which should be handler in other channels
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')
Closed: outdated
6.1
Code
Affects the content, performance, or handling of Javascript.
This ticket feels more like a support request which should be handler in other channels