Hello, I'm learning JavaScript and I wanted help to do the following functionality... What I'm trying to do is that pressing the btn1 of row 0 disables all the other buttons of the other rows (the btn2 of row zero, btn1 and btn2 from row 1, etc etc). In this example that I did to be able to guide myself, the number of rows is fixed, however the idea is that it can be applied in a table where the number of rows is not going to be fixed... I hope you can help me and thank you very much in advance
php code
<?php for ($i=0; $i <3; $i++) { ?>
<label>fila <?php echo $i; ?></label>
<button id="btn1<?php echo $i ?>" class="btn btn-primary mb-3" onclick="deshabilitar(<?php echo $i ?>)" value="<?php echo $i; ?>">btn1</button>
<button id="btn2<?php echo $i ?>" class="btn btn-primary mb-3">btn2</button>
<br>
<?php } ?>
Javascript code
var btn1=document.getElementById('btn1'),
btn2=document.getElementById('btn2'),
contador=0;
function deshabilitar(num) {
if (contador==0) {
document.getElementById('btn2'+num).disabled=true;
contador=1;
}else{
document.getElementById('btn2'+num).disabled=false;
contador=0;
}
}