php - how to count the values of the values of the dynamically added table rows using jquery -


hi have form dynamically adds table row external file when user clicks on add button , want place calculation on 1 of fields qty want calculate value of qty , show total far have written code calculate seem not work can me
here script

          $(document).ready(function(){                 $('#detail').on('keyup', '.qty', calculaterow());                 $('#addnew').click(function(){                      var ctr = $('#items').val();                     ctr++;                      $.post('job_srch.php', {ctr : ctr}, function(data) {                           $(data).appendto('#detail');                            $('#items').val(ctr);                                             });                 });   function calculaterow() {        alert("gaya");        console.log("2");         var add = 0;             $(".qty").each(function() {                     add += parsefloat(this.value);                         if (isnan(add)) {                             $('#total').val("0");                                 } else {                                   $('#total').val(add.tofixed(2));                                 }                  });   }    }); 

here php

<?php session_start(); require("includes/dbconnect.php"); include ('includes/function.php');  $zdb = $_session["zdbyear"]; mysql_select_db($zdb);  if ($_request["ctr"]){     $ctr = $_request["ctr"];     //echo '<link rel="stylesheet" href="css/chosen.css" />'; echo '<tr>     <td align="center"><input type="text" size="6" maxlength="6" maxlength="6" name="srno_'.$ctr.'" class="form-input-oth"/></td>    <td align="center"><select data-placeholder="party" style="width:300px;" name="item_'.$ctr.'" class="chzn-select-deselect" >                                   <option value=""></option>';                       $res = mysql_query("select * `items`") or die(mysql_error());                       while ($row = mysql_fetch_array($res)) {                              echo "<option value='$row[accode]'>$row[name]</option>";                       }     echo '</select></td>';     echo '<td align="center"><input type="text" id="qty" size="6" maxlength="9" maxlength="6" name="qty_'.$ctr.'" class="qty form-input-amt"/></td>                        </tr>'; } else{     echo "error"; }  ?> 

here table

            <table id="detail" border="1px" width="30%">                   <tr>                      <td width="130px" align="center"><label for=""><font color="#0099ff" size="3px">sr no.</font><span></span></label></td>                      <td width="130px" align="center"><label for=""><font color="#0099ff" size="3px">item</font><span></span></label></td>                      <td width="130px" align="center"><label for=""><font color="#0099ff" size="3px">quantity</font><span></span></label></td>                   </tr> </table> 

tthe first , obvious error found command "add += parsefloat(this.value);" not work.

the correct functions following:

function calculaterow() {    alert("gaya");    console.log("2");    var add = 0;    $(".qty").each(function() {        add += parsefloat($(this).val()); // <-- changed this.value        if (isnan(add)) {            $('#total').val("0");        } else {            $('#total').val(add.tofixed(2));        }    }); } 

you have change following row from

$('#detail').on('keyup', '.qty', calculaterow()); 

to

$('#detail').on('keyup', '.qty', calculaterow); 

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -