Ah ok, in pratica non hai bisogno del button submit, dunque l'event di ascolto lo settiamo sull'input stesso, (con input/change), vedi se puo andare cosi.
codice:const myInput = document.getElementById("result") myInput.addEventListener("input", (e) => { const myTrimStr = String(myInput.value).replaceAll(" ", "") if (myTrimStr) window.location = `https://www.example.com?var=${myTrimStr}` })