I currently have a label that changes to display the selected option from a dynamic select dropdown, but it only updates when the selection is changed. I would like it to also display the current value when the page first loads. I attempted to change 'change' to 'load' without success. Here is my current setup:
Array.prototype.forEach.call(document.getElementsByName('filename'), function(elem) {
elem.addEventListener('change', function() {
document.getElementById('mylabel').innerHTML = this.value;
});
});
<select class="select1" name="filename" id="filename">
<option>foo</option>
<option>bar</option>
</select>
<label id="mylabel"></label>