samedi 7 juillet 2018

Javascript: enable buttons on checkbox' check (both with ElementsByClass)

I am sorry I have to bother you guys with such a noob question, but I am trying and googeling since two days now and I just dont seem to find the point I need, or maybe I just don't understand it.

The case is the following: I have two rows in a table: 1. row checkbox - 2. row button I want the button only be enabled, if the checkbox in the same row is enabled. Picture for better understanding

<input type="checkbox" class="isamed" name="attr_targeted_checkbox1">
<button type='roll' class="isroll" disabled="true">

I used classes and stumbled across getElementsByClassName and the fact, that you get an array/node of objects. I tried something like this:

var buttons = document.getElementsByClassName('isroll')
var keyselects = document.getElementsByClassName('isaimed');
for (var i = 0; i < keyselects.length; i++) {
    if (keyselects[i].checked == true) {
        buttons[i].disabled = false;
        break;
        }
        }

and like 20 other codeparts and functions I found on the web, but it's not working. Maybe I have to assign the rows or something like that? Really I am just utterly desperate and my mind is full of chunk right now.

Thank you very much!




Aucun commentaire:

Enregistrer un commentaire