Jump to content

Adding Vars?


davelearning

Recommended Posts

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

Link to comment
Share on other sites

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();

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.