0
I have two inputs: what is typed in the "Title" is duplicated in the "Material Code" with the appropriate normalizations (i.e. space conversion and character removal). Is there any way - using pure Javascript - cause this "duplication" to occur only once? Something like a onBlur
in which if the user edits the "Material Code" field and comes to edit the "Title" as well, no more interference will occur in that field, since this can be edited by the same user.
Grateful from now on!
document.getElementById('f_titulo').addEventListener('input', duplica);
function duplica() {
const codigomaterial = document.getElementById('f_titulo').value;
const codigoalterado = codigomaterial.normalize('NFD').replace(/([\u0300-\u036f]|[^_0-9a-zA-Z\s])/g, '').replace(/ /g, "_").toLowerCase().substring(0, 20);
document.getElementById('f_cod').value = codigoalterado;
};
<input id="f_titulo" type="text" maxlength="60" placeholder="Título">
<input id="f_cod" type="text" maxlength="20" placeholder="Código do Material" required>
Thanks for the reply, @le314u! I ended up removing the bug from my duplication event. I will put in a separate reply, but thank you very much for your help!
– winiercape