lundi 1 mai 2017

How to get class array index for getElemetByClass name in JavaScript

everyone. I'm still new using JavaScript, I need your help to fix my problem, I try to disable checkbox after submitted. Because my checkbox value is from DB and the data will show as long as the DB have it so I'm using class="select_DB[]" in my input tag. From my knowledge class is using array index so I want to disable the checkbox that I choose I have to get the array index of the class. So how I can get the array index of the checkbox ? Need you help

//this code for disable checkbox after submit need improve I don't know how to get array index of the class
        function closeCB() {
            document.getElementByClassName("select_DB").disabled = true;
        }
        <tbody>


          <?php
              include "db_connect.php";

              $sql_select = $dt_bas->prepare("SELECT id_pegawai, nm_pegawai, tmp_lahir FROM pegawai");
              $sql_select->execute();

              while($row = $sql_select->fetch(PDO::FETCH_ASSOC)){
                        $id =  $row["id_pegawai"]; // id
                        $nm =  $row["nm_pegawai"]; // employe name
                        $tmp = $row["tmp_lahir"]; // birthday
        ?>
            <tr>
            <td><input type="checkbox" class="select_DB[]" class="select_DB[]" value=<?php echo"$id";?> <?=was_checked($id)?>/></td> <!-- This is the checkbox-->
            <td><?php echo "$id";?></td>
            <td><?php echo "$nm";?></td>
            <td><?php echo "$tmp";?></td>
            <td>
                <a href="#">Ubah</a>
                <a href="#">Detail</a>
            </td>
            </tr>

        <?php    } ?>

       



Aucun commentaire:

Enregistrer un commentaire