I am trying to use JS to update the selected value of multiple select elements, at the same time. For some reason, my JS only updates one select, not all of them on the page. Unfortunately, I am not able to change the id attribute of the select, and the various select elements need to have the same id.
How might I change the function so that ALL drop downs with id 'dropdown-test' are updated?
JS
document.getElementById('dropdown-test').value="3";
HTML
<select id="dropdown_test">
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
</select>
<select id="dropdown_test">
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
</select>
id." - if this is true, you have a requirement that means you'll be doing HTML all wrong. The whole point of Id's is that they are unique within a page!getElementById()call is passed a different ID than the one the DOM elements have.classofdropdown_testto the<select>s and use$(".dropdown_test").val(3)