Maria Hambardzumyan
Maria Hambardzumyan

Reputation: 75

Get value of td with php

I have 2 file action.php and main.php:

Currently I want to check my td value after clicking the button 'Confirm' and if value of td from main.php (name="dist_'.$iid.'" id="dist_'.$i.'") is not "-" then I want to send it to database. That td can be changed after clicking the button "Add value"

In action.php

<div class="col-sm-1">
    <button type="button" class="btn btn-primary" name="add" onclick="multiply()">Add value</button>
    <button type="button" class="btn btn-primary" name="confirm_btn">Confirm</button>
</div>

In main.php(is included in action.php) I have this type of code

        $i=0;
        if ($result = $mysqli->query($query)) {
            while ($row = $result->fetch_assoc()) {
                $iid = $row["iid"];
                echo '<tr><td><input type="checkbox" name="check[]" id="checked_'.$i
                .'" > &nbsp; </td>
                      <th scope="row">'.($i+1).'</th>
                      <td>'.$row["code"].'</td>
                      <td>'.$price.'</td>
                       <td name="dist_'.$iid.'" id="dist_'.$i.'" >-</td>
                    </tr>';
                    $i++;
                    
            }
         $result->free();
        }
        $mysqli->close();   
        

Script part of main.php

 <script>
        let i = document.querySelectorAll('[name^=check]').length;
        function multiply(){
        for (let k = 0; k<i; k++) { 
            let checkBox = document.getElementById("checked_"+k);
            if (checkBox.checked === true) {
                document.getElementById("dist_"+k).innerHTML = 100+k;          
                                            }
                                   }}
    </script>

So how can I get value of td with php?

Upvotes: 2

Views: 413

Answers (1)

Edward
Edward

Reputation: 30

You can try this

<td id="dist_td'.$i.'"><input type="hidden" name="dist_'.$iid.'" id="distbashx_'.$i.'" value="-" ></td>

in script

document.getElementById("dist_"+i).value = value; 
document.getElementById("dist_td" + i).innerHTML = value;

Upvotes: 1

Related Questions