html code:
<div class="input-group mb-2">
<span class="input-group-text">8:30 a.m</span>
<input onclick="activarodesactivar()" type="text" class="form-control" id="texto2" placeholder="">
<div class="input-group-append">
<button class="btn btn-success" onclick="alerta3()" disabled type="button" id="boton1" >Editar</button>
</div>
</div>
JS code:
function activarodesactivar(){
const htmlElements = document.querySelectorAll('#boton1');
htmlElements.forEach(elemento => elemento.disabled = false);
}
This code makes the buttons with ID button1 activate when clicking on an input, but having several inputs, what I NEED IS THAT WHEN I CLICK ON AN INPUT, THE BUTTON IS ACTIVATED AND THE OTHER BUTTONS THAT ARE DEACTIVATED UNTIL YOU CLICK IT . I hope you can help me with this code. Thank you very much for your patience.
I have refactored your code so that you have a lot less lines.
Both in the function
alerta(n)
and in theactivareditarturnomtext(n)
step, a parameter that will be the one that indicates the number of the input/button whose state you want to modify.I hope this helps you, greetings.
Last modified (08/29/2022 23:22):
I've added a new function to alter the state of text input.
It detects which are the text fields that are not being edited and puts them in disabled mode, in the same way when the editing is finished it re-enables all of them except those that have already been completed that are blocked.