Jump to content

Look for change in multiple textboxes


ivoilic

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.