Sum all input elements in jquery

Trying to figure out how to write a jquery formula that sums up all input fields starting with "pull" on the keyboard ... I try to use the code below, but nothing happens ... There are no errors and there are no updates either .... (html is at the bottom)

$(document).ready(function(){ /* sums pull total input fields */ $("input[name^='pull']").bind("keyup", "calcPullTotal"); calcPullTotal(); }); function calcPullTotal() { $("[id=totalpull]").calc( "pullnum + 0", { pullnum: $("input[name^=pull]") }, function (s){ return s.toFixed(0); }, function ($this) { var sum = $this.sum(); $("#totalpull").text( sum.toFixed(0) ); } ); } <table id="convert"> <tbody> <tr><td><input type="text" value="" name="pull0" /></td></tr> <tr><td><input type="text" value="" name="pull1" /></td></tr> <tr><td><input type="text" value="" name="pull2" /></td></tr> <tr><td><input type="text" value="" name="pull3" /></td></tr> </tbody> <tfoot><tr><td><input type="text" id="totalpull" name="totalpull" value="" /></td></tr></tfoot> </table> 
+4
source share
1 answer

Try:

 $("input[name^='pull']").bind("keyup", calcPullTotal); calcPullTotal(); 

You passed the string "calcPullTotal" as the second bind argument that function expects.

+2
source

Source: https://habr.com/ru/post/1303688/


All Articles