Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Mar 2012
    Thanked 0 Times in 0 Posts

    Postage Javascript Calculator

    I am trying to build a direct mail calculator and am taking it one step at a time. I am stuck because I need to calculate postage based on quantity entered and what size mailer they have chosen. Any help is greatly appreciate as I am a novice!

    So far I have (PLEASE NOTE the array of printing_cost_formulas are just random numbers I put to check it worked):

    <script type="text/javascript">
     var printing_cost_formulas = new Array();
    function getPrintingCost()
        var PrintingCost=0;
        var theForm = document.forms["cakeform"];
        var mailertype = theForm.elements["mailertype"];
        for(var i = 0; i < mailertype.length; i++)
                PrintingCost = printing_cost_formulas[mailertype[i].value];
        return PrintingCost;
    function calculateTotal()
        var PrintingCost = getPrintingCost();
        var divobj = document.getElementById('totalPrice');
        divobj.innerHTML = "Total Printing Cost $"+PrintingCost + mailer_quantity;
    So, as an example I need help starting down a path of defining when the user wants 1,000 of 4x6 the price is 0.50 per piece. When they want 1,000 6x9 the price is 0.55 and so on. All the postage variables are known I just have no idea how to write the 'if, else' statement or define the quantity variable within this context!! AH!

  2. #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Thanked 4,947 Times in 4,908 Posts
    Clearly homework, so I think you need to go a bit further before asking for help. See rule 1.5 here:

    Just for starters: You don't even show where [b[mailer_quantity[/b] is coming from. Nor do you show the <form> and its fields.

    Can I ask a really stupid question: Why would you do <form name="cakeform"> when the homework is about mailing costs? It's not technically wrong, of course; it just seems silly.
    Be yourself. No one else is as qualified.


Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts