Changed from document.onchange to window.onchange