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); } ); Link to comment https://forums.phpfreaks.com/topic/182270-jquery-help-execute-function/ 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> Link to comment https://forums.phpfreaks.com/topic/182270-jquery-help-execute-function/#findComment-961805 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 Link to comment https://forums.phpfreaks.com/topic/182270-jquery-help-execute-function/#findComment-961817 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 Link to comment https://forums.phpfreaks.com/topic/182270-jquery-help-execute-function/#findComment-961821 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(); } ); Link to comment https://forums.phpfreaks.com/topic/182270-jquery-help-execute-function/#findComment-961827 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.