从追加表中获取id并在算术javascript中使用它

问题描述 投票:0回答:1

我正试图从追加表中获取id并将其用于算术。

这是我附加表格及其在php中的模态

<tbody>

    <tr class="item-row"  id="item-row" onload="calculate()">

        <?php

        foreach ($conn->query("SELECT * FROM panapricelist") as $info){

            echo "<td><input type='checkbox' id='promotitle' name='check' value='".$info['ProductId']."' ></td>";
            echo "<td><textarea rows='4' cols='7' maxlength='60'  name='pcode' class='pcode' id='ProductCode' disabled>".$info['ProductCode']."</textarea></td>";
            echo "<td><br><textarea rows='5' cols='40' maxlength='50' name='puse' id='productUse' disabled>".$info['ProductUse']." </textarea></td>";
            echo "<td><br><textarea rows='4' cols='50' maxlength='50' name='pdesc' id='productDesc' disabled>".$info['ProductDesc']."</textarea></td>";
            echo "<td id='msrp'><textarea rows='4' cols='10' maxlength='50' name='Msrp' class='productMsrp' id='productMsrp' disabled>".$info['Msrp']."</textarea></td>";
                echo "<td style='width: 10%;' id='cost'><textarea rows='4' cols='10' name='Dealerphp' maxlength='50' class='cost' id='cost' disabled>".$info['DealerPhp']."</textarea></td</td></tr>";

            }
            ?>

</tbody>

这是追加javascript。

<script type="text/javascript">

    $(document).ready(function() {
        $("#button_add").click(function() {
            var favorite = [];
            $.each($("input[name='check']:checked").each( function() {
                // favorite.push($(this).val());

                var getRow = $(this).parents('tr'); //variable for the entire row
                var value =  (getRow.find('td:eq(1)').html()); // Product Code
                var value1 = (getRow.find('td:eq(2)').html()); // for Suggested Product Use
                var value2 = (getRow.find('td:eq(3)').html()); // for product Description
                var value3 = (getRow.find('td:eq(4)').html()); // for MSRP PHP
                var value4 = (getRow.find('td:eq(5)').html()); // for Dealer PHP

                $('#item-row').append('<tr><td class="item-name"><textarea class="productid" id="prc" value="'+ value +'</textarea></td><td class="item-name"><textarea class="productuse" id="productuse" value= "' + value1 + ' </textarea> </td><td class="item-name"><textarea class="description" id="description" value= "' + value2 +' </textarea></td><td class="item-name"><textarea class="msrp" id="msrp" value= "' + value3 + ' </textarea>  </td><td class="item-name"><textarea class="cost" name="cost" id="'+ value4 + ' </textarea></td><td class="item-name"><textarea class="qty" id="qty" name="qty"></textarea></td><td class="item-name"><textarea id="price" class="price" name="price" disabled></textarea></td></tr>');    

                console.log(value4);

            }));
        });
    });

</script>

这里是获取id的算术javascript,乘以qty的列并得到总数。

function update_price() {
  var row = $(this).parents('.item-row');
  var price = row.find('.cost').val().replace("₱" ,"") * row.find('.qty').val();
  price = roundNumber(price,2);
  isNaN(price) ? row.find('.price').html("N/A") : row.find('.price').html("₱" +price);

  update_total();
  update_balance();
  update_ftotal();

}

function bind() {
  $(".cost").blur(update_price);
  $(".qty").blur(update_price);
}
javascript php append arithmetic-expressions
1个回答
0
投票

得到它了

function update_price() {
                            var row = $(this).parents('tr');
                            var a , w = 0;
                            var a = row.find('.cost').val().replace(/\,/g,''); 
                            var w = row.find('.qty').val().replace(/\,/g,'');

                            var price = Number(a) * Number(w);

                            price = roundNumber(price,2);
                            isNaN(price) ? row.find('.price').html("N/A") : row.find('.price').html("₱" +price);

                            update_total();
                            update_balance();
                            update_ftotal();

                        }

                        function bind() {
                            $(".cost").blur(update_price);
                            $(".qty").blur(update_price);
                        }
© www.soinside.com 2019 - 2024. All rights reserved.