How can i bind two input fields together so that a given change in one is reflected in the other input field using Vanillla Js
What have you tried so far, do you have any code?
The way it’s done is that you listen for events on the inputs. When the event you want to listen to occurs, set the value of the unfocussed input/s to whatever the current value of the focussed one is. There are various ways to implement that. So same question.
1 Like
hey there, actually i have just figured it out but this is the code though, thanks
const firstInput = document.querySelector('.first-input');
const secondInput = document.querySelector('.second-input');
firstInput.addEventListener('input', () => {
secondInput.value = firstInput.value;
})
secondInput.addEventListener('input', () => {
firstInput.value = secondInput.value;
})
This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.