首页 > 解决方案 > Access Data on click event from table

问题描述

i have table "login" and listing the data from mysql using php into table in html.

<table class="table">
                            <thead class="thead-dark">
                            <tr>
                                <th scope="col">Sl.NO</th>
                                <th scope="col">Name</th>
                                <th scope="col">Username</th>
                                <th scope="col">Mobile</th>
                                <th scope="col">Join Date</th>
                                <th scope="col">Action</th>

                            </tr>
                            </thead>
                            <tbody>
                                <?php
                                if($req_result->num_rows > 0)
                                    {
                                        while($req_row = $req_result->fetch_assoc()) {
                                            $i+=1;
                                            $reqmail = $req_row['username'];
                                            $reqmobile = $req_row['id'];
                                            $reqname = $req_row['name'];
                                            $join_date = $req_row['join_date'];

                                            ?>

                                            <tr>
                                              <th scope="row"><?php echo $i ;?></th>
                                              <td><?php echo $reqname ;?></td>
                                              <td><?php echo $reqmail ;?></td>
                                              <td><?php echo $reqmobile ;?></td>
                                              <td><?php echo $join_date ; ?></td>
                                              <td><button type="submit" value="'.$reqmobile.'" class="btn btn-primary" data-toggle="modal" data-target="#confirm">Approve</button></td>
                                            </tr>

                                            <?php
                                        }
                                    }
                                ?>

                          </tbody>
                        </table>

i want to acccess that button value on click, and process another queries.the tbale "login" has multiple datas. how can i do it?

标签: javascriptphphtmlmysqlpost

解决方案


尝试使用这个。如果出现问题,请告诉我。干杯

//catch html button with js assigned to variable button
let button = document.querySelector('.btn btn-primary');

//listen for the click
button.addEventListener('click', function(){
   button.value;
});
// console log the the value of button
console.log(button);

推荐阅读