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); }) }); Link to comment https://forums.phpfreaks.com/topic/265649-look-for-change-in-multiple-textboxes/ 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 Link to comment https://forums.phpfreaks.com/topic/265649-look-for-change-in-multiple-textboxes/#findComment-1361519 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! Link to comment https://forums.phpfreaks.com/topic/265649-look-for-change-in-multiple-textboxes/#findComment-1361560 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.