Question:
Guys I have 2 input:
<input name='nome1'>
<input name='nome2'>
I need to create a javascript that clears name2 when the value of name1 is changed.
Can anyone help me to make this very simple?
Answer:
This is simple:
var nome1 = document.querySelector('[name="nome1"]');
var nome2 = document.querySelector('[name="nome2"]');
nome1.addEventListener('change', function() {
nome2.value = '';
});
jsfiddle: https://jsfiddle.net/tvrgsou2/
That way when the input changes, nome2
is deleted. If you want, you can also do it on keyup
or another event depending on the functionality you want to implement.