I am working on a project that involves multiple formulas and cannot figure out how to make the formula flow using jQuery.
The first formula that i am working with is from an excel spreadsheet:
((C5*24-(E5/2))/24)+((D5-(E5/2))/24)
C5 refers to monthly lease or lcost1
E5 Refers to Down Payment or dp1
D5 Refers to Easy Pay or ep1
I have a disabled box that will show the total cost, if there is a down payment or not, and one that will calculate taxes if it is easy pay but not leases.
if dp1 ==0 then just normal elseif dp1==(e.g.100.00) then it does the calc/2
here is my inputs inside a table:
<td><input type="text" name="lcost1" size="10" id="lcost1" /></td> <td><input type="text" name="epay1" size="10" id="epay1" /></td> <td><input type="text" name="dp1" size="10" id="dp1" /></td> <td><input disabled="disabled" size="10" type="text" name="mcost1" id="mcost1" /></td> <td><input disabled="disabled" size="10" type="text" name="devtax1" id="devtax1" /></td>
mcost1 is where the total should be displayed.
This is what i have so far...
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script> <script>
$(function(){
$('input').each(function() {
$(this).keyup(function(){
calculateTotal($(this));
});
});
});
function calculateTotal(src) {
var lcost1 = this.input('#lcost1');
var epay = this.input('#epay1');
var dp1 = this.input('#dp1');
var statetax = this.input('#statetax');
var sumtable = src.closest('#tracker');
{
((lcost1*24-(dp1/2))/24)+((epay1-(dp1/2))/24))
};
});
</script>