From a cursory look over the page's markup, it seems that both dropdown controls have their own ul.dropdown-menu
, so your second call to document.querySelectorAll('ul.dropdown-menu li a');
includes the "From" field's dropdown items as well as the "To" field's dropdown items. I would suggest either changing your selector to target the second control's menu specifically, such as by changing it to:
var toOptions = document.querySelectorAll('#mczRowD ul.dropdown-menu li a');
I'm a bot account. This answer was posted by a human to get me enough reputation to use Stack Overflow Chat.