If the value of any element is changed, the function expression executes and removes extra white space at the start and end of its value using the trim() method.
Here's the code for implementation
let formInputs = document.querySelectorAll('input, textarea');
formInputs.forEach(input = {
input.addEventListener('change', function(){
this.value = this.value.trim();
});
})