2
I have several inputs with readonly="true" which, when pressing the edit button, it should change to readonly="false", but I am able to do this only if I create 1 script for each input.
Could I make 1 script to change in all?
I tried to leave everyone with the same ID, but it changes only the first one. The inputs:
<div class="form-group">
<h2>Accomodation</h2>
<div class="form-group">
<label>Name:</label>
<input class="form-control" id="myText" value="Test" readonly="true" />
</div>
<div class="form-group">
<label>Email:</label>
<input class="form-control" id="myText" value="Test" readonly="true"/>
</div>
<div class="form-group">
<label>Email Copy:</label>
<input class="form-control" id="myText" value="Test" readonly="true"/>
</div>
</div>
The script:
<script>
function myFunction() {
document.getElementById("myText").readOnly = false;
}
</script>
I searched the internet but only found how to change 1 input, several did not find anything.
Thank you in advance!
Thank you for the answer! It worked perfectly, but it lacked a detail: I also have other inputs that are readonly="true" that won’t be changed when I click the button. This method changes all inputs. It would have some solution for this?
– Valdir Amorim
@Valdiramorim depends on the structure of the HTML. So you put in the question you can’t guess. Test different selectors here
querySelectorAll('input.form-control');
as I suggested at the end of the answer. You can even use[readonly="true"]
on the selector.– Sergio