I am creating an investment calculator that takes user input from six pages and stores them in PHP $_SESSION variables. On the final page i take the $_SESSION variables form PHP and JSON.parse them to Javascript like so:
var cash = parseInt(JSON.parse( '<?php echo json_encode($cash_flow); ?>'));
I then run the variables through a formula to find a score like so:
function SCORE( cash, comp, num_months) {
var total1 = (cash - comp )/( num_months*12);
var total2 = total1/2.5;
var total3 = total2*100;
var dvTotal = total3;
return dvTotal;
}
I then use JQuery to output the score to the DOM.
I then have a section with a display of each of the users original input with a + and - next to them allowing the user to update their original input.
$('#cashMinusBtn').click(function(){
$('#cashFlowOutput').html(cash-=1000);
var newCash = $('#cashFlowOutput').html();
SCORE( newCash );
$('#dvTestOut').html(scoreTotal);
Here is the HTML used to output the user data:
div class="container-fluid pro-table">
<div class="row">
<div class="col-md-12 tooltip-row">
<h4>Increase or Decrease value of initial entry to see how your dv<strong>SCORE</strong> would be effected:</h4>
</div>
</div>
<div class="row tooltip-display">
<div class="col-md-2 outputBox">
<p>Cash Flow</p><br>
<p id="cashFlowOutput"></p><br>
<button class="table-button" id="cashMinusBtn">-</button><button class="table-button" id="cashPlusBtn">+</button>
</div>
<div class="col-md-2 outputBox">
<p>Purchase Price</p><br>
<p id="purchaseOutput"></p><br>
<button class="table-button" id="purchaseMinusBtn">-</button><button class="table-button" id="purchasePlusBtn">+</button>
</div>
<div class="col-md-2 outputBox">
<p>Down Payment</p><br>
<p id="downOutput"></p><br>
<button class="table-button" id="downMinusBtn">-</button><button class="table-button" id="downPlusBtn">+</button>
</div>
<div class="col-md-2 outputBox">
<p>Interest Rate</p><br>
<p id="interestOutput"></p><br>
<button class="table-button" id="interestMinusBtn">-</button><button class="table-button" id="interestPlusBtn">+</button>
</div>
<div class="col-md-2 outputBox">
<p>Months Financed</p><br>
<p id="monthsOutput"></p><br>
<button class="table-button" id="monthsMinusBtn">-</button><button class="table-button" id="monthsPlusBtn">+</button>
</div>
<div class="col-md-2 outputBox">
<p>Compensation</p><br>
<p id="compOutput"></p><br>
<button class="table-button" id="compMinusBtn">-</button><button class="table-button" id="compPlusBtn">+</button>
</div>
I would like to grab the new data updated by the user via + or -, send it through the formula, and update the score displayed.
I have no problem grabbing the updated data with var newCash = $('#cashFlowOutput').html();
But i'm having trouble pushing the newCash back through the formula and updating the score.
I'll include the repo for this material, i understand that some of the work has vulnerabilities but it is still and work in progress on a local server: https://github.com/DLzer/YarmouthApp/blob/master/finalPage.php
This is my first serious attempt at an application so i'm unsure if i'm making a lot more work for myself than needs to be done. Any critiquing appreciated.