I have an input field and multiple input fields, the original input field is the primary field that gets submitted.
So, I need to mirror one field to the main field.
I tried watching the keyup
and change
events but when the user pastes with the mouse it does not work, because the event is triggered before the user presses paste
and not after it.
- I am not sure that this is the best way to mirror two fields, so I am asking you if you have better methods of doing it
- Is there an event that can be triggered after the paste is pressed?
CodePudding user response:
Instead of triggering on key/mousevents, you could try using an "input" event on the input element you would like to mirror.
const ogInput = document.getElementById("og")
const mirrorInput = document.getElementById("mirror")
ogInput.addEventListener("input", () => {
mirrorInput.value = ogInput.value
})
<input type="text" id="og" />
<input type="text" id="mirror" />