I have two inputs fields:
<input type="text" id="one" name="one" />
<input type="text" id="two" name="two" />
I want a function to copy the text of the first input automatically when we click on the second input without using Jquery
Thanks
To check if the user clicks on the <input> element, add an event listener to it.
Then, get the value of the first text field using the value property.
Here is your code:
document.getElementById('two').addEventListener("click", function() {
this.value = document.getElementById('one').value;
});
<input type="text" id="one" name="one" />
<input type="text" id="two" name="two" />
Here is a living demo: https://codepen.io/marchmello/pen/XWmezNV?editors=1010