davelearning Posted January 20, 2011 Share Posted January 20, 2011 Hi all, is it possible to add vars together to come to a total? Currently my valuesa re just printed in a line and not added together: <script> function displayVals() { var serverCost = $("#server").val(); var ramCost = $("#ram").val(); var storageCost = $("#hdd").val(); var ipCost = $("#ip").val(); var totalCost = serverCost + ramCost + storageCost + ipCost; $("#price").html("<b>Server Cost:</b> $" + serverCost + "<br><b>Extra Ram:</b> $" + ramCost + "<br><b>Storage Space:</b> $" + storageCost + "<br><b>Extra IP's:</b> $" + ipCost + "<br><br><b>Total Cost:</b> $" + totalCost ); } $("select").change(displayVals); displayVals(); </script> Thanks Quote Link to comment https://forums.phpfreaks.com/topic/225038-adding-vars/ Share on other sites More sharing options...
davelearning Posted January 20, 2011 Author Share Posted January 20, 2011 Solved function displayVals() { var serverCost = $("#server").val(); var fservercost = parseFloat(serverCost); var ramCost = $("#ram").val(); var framcost = parseFloat(ramCost); var storageCost = $("#hdd").val(); var fstorageCost = parseFloat(storageCost); var ipCost = $("#ip").val(); var fipcost = parseFloat(ipCost); var totalValue = fservercost + framcost + fstorageCost + fipcost; $("#price").html("<b>Server Cost:</b> $" + serverCost + "<br><b>Extra Ram:</b> $" + ramCost + "<br><b>Storage Space:</b> $" + storageCost + "<br><b>Extra IP's:</b> $" + ipCost + "<br><br><b>Total Cost:</b> $" + totalValue ); } $("select").change(displayVals); displayVals(); Quote Link to comment https://forums.phpfreaks.com/topic/225038-adding-vars/#findComment-1162334 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.