Hello and welcome to our community! Is this your first visit?
Register
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
    Posts
    1
    Thanks
    0
    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):

    Code:
    <script type="text/javascript">
     var printing_cost_formulas = new Array();
     printing_cost_formulas["4x6"]=10+5;
     printing_cost_formulas["5.5x8.5"]=25;
     printing_cost_formulas["6x9"]=35;
     
    
    function getPrintingCost()
    {  
        var PrintingCost=0;
        var theForm = document.forms["cakeform"];
        var mailertype = theForm.elements["mailertype"];
        for(var i = 0; i < mailertype.length; i++)
        {
            if(mailertype[i].checked)
            {
                PrintingCost = printing_cost_formulas[mailertype[i].value];
                break;
            }
        }
        return PrintingCost;
    }
         
    function calculateTotal()
    {
        var PrintingCost = getPrintingCost();
        
        var divobj = document.getElementById('totalPrice');
        divobj.style.display='block';
        divobj.innerHTML = "Total Printing Cost $"+PrintingCost + mailer_quantity;
    
    }
    
    </script>
    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
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,020
    Thanks
    75
    Thanked 4,323 Times in 4,289 Posts
    Clearly homework, so I think you need to go a bit further before asking for help. See rule 1.5 here:
    http://www.codingforums.com/rules.htm

    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.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  

    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
    •