ivoilic Posted July 14, 2012 Share Posted July 14, 2012 So I have a series of textboxes and when any of the values are changed I want JS to apply some basic calculations to each and then display the sum. I can do this where it detects the change in one textbox, but I am not sure how to get it to detect a change in any of the textboxes other than copy and pasting the code and changing the id for each. $(document).ready(function()//When the dom is ready { $("#def").keyup(function() { //if theres a change in var def = $("#def").val(); var acc = $("#acc").val(); //Calculate Each Cost var def_cost = def * 5; var acc_cost = acc * 5; //Total Costs var points= Number(acc_cost) + Number(def_cost); //Display Costs in Span $("#pointspreview").html(points); }) }); Quote Link to comment Share on other sites More sharing options...
Mahngiel Posted July 14, 2012 Share Posted July 14, 2012 You need to map all of the inputs and apply a function across it. consider this fiddle Quote Link to comment Share on other sites More sharing options...
ivoilic Posted July 14, 2012 Author Share Posted July 14, 2012 Yeah problem solved i modified to the example you gave me to this: http://jsfiddle.net/kKNNE/14/ It's exactly what I need! THANKS! 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.