Question

I want to be able to take the value from the calcOrderTotal input and then divide it and display the divided output in another input (for example, to show the Order Total price, and then what the order total 36 monthly lease price would be). I sort of attempted to do it with the "calc36Month" function, but I know it's not right.

function calcOrderTotal() {

var orderTotal = 0;

var productSubtotal = $("#product-subtotal").val() || 0;
var serverPrice = $('.server-radio:checked').val() || 0;
var equipmentPrice = $('.equipment-radio:checked').val() || 0;
var underTotal = $("#under-box").val() || 0;

var orderTotal = parseFloat(CleanNumber(productSubtotal)) + parseFloat(CleanNumber(serverPrice)) + parseFloat(CleanNumber(equipmentPrice));    

$("#order-total").val(CommaFormatted(orderTotal));

$("#fc-price").attr("value", orderTotal);

}

The calcOrderTotal function is then redirected to this HTML input and displays a dollar value (this does work):

<input type="text" class="total-box" value="$0" id="order-total" disabled="disabled" name="order-total"></input>

I want to be able to take the OrderTotal dollar value and divide it by 36 months and input the 36 month lease value into another input. Here is an example of what I'm looking for (I know this does not work):

function calc36Month() {

    var 36Month = 0;

    var orderTotal = $("#order-total").val() || 0;

    var 36Month = parseFloat(CleanNumber(orderTotal)) / 36;    

    $("#36-monthly-total").val(CommaFormatted(36Month));

    $("#fc-price").attr("value", 36Month);

}

How can I do this?

Was it helpful?

Solution

Here ya go:

function calcOrderTotal() {
    var orderTotal = 0;

    var productSubtotal = $("#product-subtotal").val() || 0;
    var serverPrice = $('.server-radio:checked').val() || 0;
    var equipmentPrice = $('.equipment-radio:checked').val() || 0;
    var underTotal = $("#under-box").val() || 0;

    var orderTotal = parseFloat(CleanNumber(productSubtotal)) + parseFloat(CleanNumber(serverPrice)) + parseFloat(CleanNumber(equipmentPrice));    

    $("#order-total").val(CommaFormatted(orderTotal));
    $("#fc-price").attr("value", orderTotal);
    if (orderTotal > 0) {
        calcMonthly(orderTotal);
    }
}

EDIT: Edited per request.

function calcMonthly(total) {
    var pmt1 = total / 36;
    var pmt2 = total / 24;
    var pmt3 = total / 12;
    $("#monthly-36").val(CommaFormatted(pmt1));
    $("#monthly-24").val(CommaFormatted(pmt2));
    $("#monthly-12").val(CommaFormatted(pmt3));
    //$("#fc-price").attr("value", pmt1); // what is the purpose of this?
}

Avoid using numeric digits as variable names, element ID's or CSS classes, or beginning any of the aforementioned references with a number. Begin all variable names, ID's and classes with a letter.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top