-1

ここに画像の説明を入力たとえば、金額のパーセンテージを取得したいフォームがあります。金額を 100 にすると、10 と入力されるので、目的の出力は 10 になります。出力が 110 (100 + 10) になるように、パーセンテージの金額を金額に追加したいのですが、パーセンテージを取り出すことはできますが、そうではありません。量に追加され、これらのフィールドは動的に生成された入力になります。

これが私のコードです:

    $(document).ready(function(){
        $('#detail').on('keyup', '.rent, .stperc, .st, .stamt, .cal', calculateRow);

            function calculateRow() {
                     var $row   = $(this).closest('tr');
                     var value  = parseFloat($row.find('.stperc').val());
                     var value2 = parseFloat($row.find('.rent').val());


                     var stamt  =  parseFloat($row.find('.stamt').val((value * value2) / 100));

                     var cost = stamt + value2;
                     console.log(cost);
                     if (isNaN(cost)) {
                         $row.find('.cal').val("0");
                     } else {
                         $row.find('.cal').val(cost);
                     }

            }

    });

テキストボックスを生成する私のphpコードは次のとおりです。

                while ($row = mysql_fetch_object($query)){
                       echo "<tr>";
                       echo "<td align='center'>";
                       echo "<input type='text' class='form-input-rate' name=\"locno_$ctr\" value=\"$row->locno\" $stylen readonly>";
                       echo "</td>";
                       echo "<td align='center'>";
                       echo "<input type='text' class='form-input-rate' name=\"ledger_$ctr\" value=\"$row->custcode\" $stylen readonly>";
                       echo "</td>";
                       echo "<td align='center'>";
                       echo "<input type='text' class='form-input-rate' name=\"name_$ctr\" value=\"$row->name\" $stylev readonly>";
                       echo "</td>";
                       echo "<td align='center'>";
                       echo "<input type='text' class='form-input-rate' name=\"deposit_$ctr\" value=\"$row->deposit\" $stylen >";
                       echo "</td>";
                       echo "<td align='center'>";
                       echo "<input type='text' class='rent form-input-rate' name=\"rent_$ctr\" value=\"$row->rent\" $stylen >";
                       echo "</td>";
                       echo "<td align='center'>";
                       echo "<input type='text' class='stperc form-input-rate' name=\"stperc_$ctr\" value=\"$row->stperc\" $stylen >";
                       echo "</td>";
                       echo "<td align='center'>";
                       echo "<input type='text' class='stamt form-input-rate' name=\"st_$ctr\" value=\"$row->stamt\" $stylen >";
                       echo "</td>";
                       echo "<td align='center'>";
                       echo "<input type='text' class='cal form-input-rate' name=\"total_$ctr\" value=\"$row->totamt\" $stylen readonly>";
                       echo "<input type='hidden' name=\"accode_$ctr\" value=\"$row->accode\">";
                       echo "</td>";
                       echo "</tr>"; 
                       $ctr++;
                }
4

1 に答える 1