从附加表获取ID并在算术javascript中使用它

时间:2018-10-07 09:05:48

标签: javascript php append arithmetic-expressions

我正在尝试从附加表中获取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,乘以qty列并获得总数的算术javascript。

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);
}

1 个答案:

答案 0 :(得分: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);
                        }