everisk Posted November 20, 2009 Share Posted November 20, 2009 Hi I'm a jquery newbie. I'm trying to sum a column with below code on page load. it works fine. But I also want to update the total when the input changes. How do I do that? I dont even know how to specify a function in jquery Basically, something like <input type="text" name="whatever" id="whatever" class="regular" onBlur="runJqueryFunction()" /> $(document).ready( function() { var total=0; $('.regular').each( function() { total = parseInt(total) + parseInt(this.value); } ); $('#total_regular').text(total); } ); Quote Link to comment Share on other sites More sharing options...
rajivgonsalves Posted November 20, 2009 Share Posted November 20, 2009 <script type="text/javascript"> function totalIt() { var total=0; $('.regular').each( function() { total = parseInt(total) + parseInt(this.value); } ); $('#total_regular').text(total); } $('.regular').blur(totalIt); </script> Quote Link to comment Share on other sites More sharing options...
everisk Posted November 20, 2009 Author Share Posted November 20, 2009 Thanks for the quick reply Rajiv I got this error on Firebug missing ) after argument list [break on this error] $('.regular').blur(totalIt);\n Quote Link to comment Share on other sites More sharing options...
rajivgonsalves Posted November 20, 2009 Share Posted November 20, 2009 the syntax looks correct you will have to put the function outside and put the blur in the onready function Quote Link to comment Share on other sites More sharing options...
everisk Posted November 20, 2009 Author Share Posted November 20, 2009 I still get the same error. But thanks! I got it working by $(document).ready( function() { totalIt(); } ); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.