Grow your CSS skills. Land your dream job.

downloadable order form, having problems coding decimals

  • # March 4, 2009 at 5:41 pm

    Hello,

    Hopefully someone can help me here, i recently downloaded the template from this site for the Order form Chris did recently and im having a slight issue, the prices that i have recently changed in the HTML code, has been changed to decimal’s, so basically cents in some cases instead of dollars. The java will calculate the decimals in the row totals for the products, but then it comes to the sub total and grand total, it decides to not include a decimal and round to a whole number, with the industry i work for and am currently designing a site for them, i was wondering if anyone could help me, I’m not sure exactly what part of the code you would need as i am not that fluent with Java, but any help would be greatly appreciated, if you need the code let me know with your response and i can post it

    Thanks

    zzzCL

    # March 5, 2009 at 1:48 am

    you are suppose to post the code first. That will get you your help much faster. without seeing your code, there is no way to tell what you did wrong. Off the top of my head, it might be a problem with your variables. There are different variables for different maths. Some round up, some down. You may need to declare your variables as a float type rather than an int. Post your code.

    # March 5, 2009 at 8:32 am

    here is the code, thanks for the quick response it is greatly appreciated.

    Code:
    function IsNumeric(sText)

    {
    var ValidChars = “0123456789.”;
    var IsNumber=true;
    var Char;

    for (i = 0; i < sText.length && IsNumber == true; i++)
    {
    Char = sText.charAt(i);
    if (ValidChars.indexOf(Char) == -1)
    {
    IsNumber = false;
    }
    }
    return IsNumber;

    };

    function calcProdSubTotal() {

    var prodSubTotal = 0;

    $(".row-total-input").each(function(){

    var valString = $(this).val() || 0;

    prodSubTotal += valString;

    });

    $("#product-subtotal").val(prodSubTotal);

    };

    function calcTotalPallets() {

    var totalPallets = 0;

    $(".num-pallets-input").each(function() {

    var thisValue = $(this).val();

    if ( (IsNumeric(thisValue)) && (thisValue != '') ) {

    totalPallets += thisValue;

    };

    });

    $("#total-pallets-input").val(totalPallets);

    };

    function calcShippingTotal() {

    var totalPallets = $("#total-pallets-input").val() || 0;
    var shippingRate = $("#shipping-rate").text() || 0;
    var shippingTotal = totalPallets;

    $("#shipping-subtotal").val(shippingTotal);

    };

    function calcOrderTotal() {

    var orderTotal = 0;

    var productSubtotal = $("#product-subtotal").val() || 0;
    var shippingSubtotal = $("#shipping-subtotal").val() || 0;

    var orderTotal = productSubtotal + shippingSubtotal;
    var orderTotalNice = "$" + orderTotal;

    $("#order-total").val(orderTotalNice);

    };

    $(function(){

    $('.num-pallets-input').blur(function(){

    var $this = $(this);

    var numPallets = $this.val();
    var multiplier = $this
    .parent().parent()
    .find("td.price-per-pallet span")
    .text();

    if ( (IsNumeric(numPallets)) && (numPallets != '') ) {

    var rowTotal = numPallets * multiplier;

    $this
    .css("background-color", "white")
    .parent().parent()
    .find("td.row-total input")
    .val(rowTotal);

    } else {

    $this.css("background-color", "#ffdcdc");

    };

    calcProdSubTotal();
    calcTotalPallets();
    calcShippingTotal();
    calcOrderTotal();

    });

    });

# March 5, 2009 at 4:00 pm

Any chance of a live link so we can see the problem in action?

# March 5, 2009 at 5:39 pm

The website itself is not live, i can try and access the box i have in Chicago to temporarily host this page, not sure if im going to be able to do that (other owner might get a little upset LOL), in case i cannot, i will update you as to what i have tried, i can now get decimals in the subtotal and the order total, but it adds way to many zeros, both in front of the price, and after it. Sorry if i Dont get a live link up, if not ill screenshot it and post what its doing.

Thanks for the quick responses guys

zzzCL

# March 6, 2009 at 6:18 am

then why not have a holding page, so that anyone going to the main site, will be directed to that, and show us the page you want help with???

the client need not know, plus if the client wants it working, and you need help, then they got to be prepared to put up with people seeing the site for helping purposes

# August 1, 2009 at 1:39 pm

You can show a code in which the subtotal showing decimals bandstand?

Viewing 7 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".