This Javascript is not working in IE or Edge. Anyone got any ideas?

Viewed 189

I have the following script that copies on select box to the other. It work in chrome,Opera and Firefox but not Edge or IE.

<select id="domainsource"><option>yes</option><option>no</option></select>
<select id="domaintarget"><option>yes</option><option>no</option></select>

<script>
var input = document.querySelector('#domainsource');
var messages = document.querySelector('#domaintarget');
input.addEventListener('input', function()
{
messages.value =  input.value;
});
</script>
2 Answers

Unfortunately this is simply a browser support issue. IE 11 and pre-chromium edge do not support the input event on select elements. See note #3 on Can I Use.

Works for me in IE11

var input = document.querySelector('#domainsource');
var messages = document.querySelector('#domaintarget');

function changed() {
  messages.value = input.value;
};
<select id="domainsource" onchange="changed()">
  <option>yes</option>
  <option>no</option>
</select>
<select id="domaintarget">
  <option value="yes">yes</option>
  <option value="no">no</option>
</select>

Related