With every purchase, the items should reduce in quantity from the bincard table.
My code is not working.  What is the solution for this.     
<button type="submit" name="btnSubmit" onclick="reduce();" class="btn btn-success">
    <i class="fa fa-print"></i>Print
</button>
<script type="text/javascript">
    function reduce() 
    {                                                   
        var rows = document.getElementById("TableA")
                           .getElementsByTagName("tbody"[0]
                           .getElementsByTagName("tr").length;
        for(var x=0; x<rows; x++)
        {
            var id = document.getElementById("TableA")
                             .getElementsByTagName("tbody")[0]
                             .getElementsByTagName("tr")[x]
                             .getElementsByTagName("td")[4]
                             .innerHTML;
            var qu = document.getElementById("TableA")
                             .getElementsByTagName("tbody")[0]
                             .getElementsByTagName("tr")[x]
                             .getElementsByTagName("td")[5]
                             .innerHTML;
            var update_qu = "update bincard set QtyBalance='$qu' where BinId='$id'";
        }
        var run_qu = mysqli_query($con, $update_qu);
    }
</script>
 
    