I'm with a form with different fields (name, surname, etc.)
How could I do in JavaScript in the field that has the focus when I press a "Clean" button. And apart, I have the RESET button that cleans all the fields.
This would be my HTML for example:
<form>
<label>Nombre:</label><br>
<input type="text" id="nombre" value="" placeholder="Nombre"/><br>
<label>Primer Apellido:</label><br>
<input type="text" id="apellido1" value="" placeholder="Primer Apellido"/><br>
<label>Segundo Apellido:</label><br>
<input type="text" id="apellido2" value="" placeholder="Segundo Apellido"/><br>
<label>Contraseña</label><br>
<input type="password" id="password" value="" placeholder="Password" /><br>
<input type="reset" id="reset" value="Reiniciar">
<input type="button" id="limpiar" value="Limpiar Campo">
<input type="button" id="enviar" value="Enviar">
</form>
And this is the JS:
window.onload = inicio;
function inicio(){
document.getElementById("limpiar").addEventListener('click',limpiar);
}
function limpiar(){
var activo = document.activeElement.id;
activo.innerHTML = "";
}
The issue is that I want to clean the text field that has the focus, but of course, that field loses it immediately when you click clean.
I hope it's clearer now what I'm looking for. Thanks.