I have an interactive graphic with a <select>
element (a drop-down menu). It works fine — except in Internet Explorer.
Essentially, I can't programmatically change the <select>
element's selected (and hence displayed) value in IE. I need to do this programmatically because the <option>
elements within the <select>
element are populated dynamically each time the user makes a change. My program (not the one below):
- listens for the user to change the
<select>
element; - stores the selected value as a variable;
- creates a new datalist, based on the selection, for the drop-down menu;
- uses this datalist to re-populate the
<option>
elements in the<select>
element; and - sets the displayed value in the
<select>
element as the selected variable.
A version of the problem follows (I code with d3.js
). The code below changes the <select>
element's value every second. It works fine in most browsers — but try viewing it in IE:
<select></select>
<h1></h1>
<script src="https://d3js.org/d3.v4.min.js"></script>
<script>
selector = d3.select("select"),
answer = d3.select("h1"),
fruit = ["apricots", "apples", "bananas", "grapefruit", "lemons", "oranges", "plums", "tangerines"];
// fill the drop-down menu with fruit
selector.selectAll("option")
.data(fruit)
.enter().append("option")
.text(function(d) { return d; });
// display the selected value under the menu
answer.text(selector.property("value"));
// change the selection every second
changeValue = d3.interval(function() {
selector.property("value", fruit[Math.random() * fruit.length | 0]);
answer.text(selector.property("value"));
}, 1000);
</script>