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 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Jun 2014
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    help with script for banners

    Hello my friends, im sure this will sound like a stupid question, but im "stuck" in my code.
    I made a script to "sell" banners and everything is working very good, EXCEPT, the m2 total output beeing added to quantity field.

    In the first part, users insert im meters height and width and the script will convert to m2. DONE
    Second part users insert quantity and script will give the cost. DONE

    But, what i want/need is the quantity beeing filled automaticly with the m2 total.

    Can someone please help me?

    Thx in advance


    PHP Code:

    <html>
    <
    head>
    <
    title>Banner Cost Calculator</title>
    <
    meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <
    script type="text/javascript">



    function 
    calcArea(L,W)
    {return 
    L*W;}


    function 
    calc(f,W,L){
    var 
    width parseFloat(W);
    var 
    length parseFloat(L);
    var 
    area calcArea (length,width);
    //var squaremeter = calcSquaremeter();

    f.value calcArea(length,width);
    //f.squaremeterBox.value = squaremeter;
    }
    </script>

      <script>
    function Total(qty,ud,total,value){
     qty=document.getElementById(qty);
     ud>0?qty.value++:qty.value--;
     qty.value=Math.max(qty.value,0);
     document.getElementById(total).value=qty.value*value;
    }
      </script>
    <style type="text/css">
    label {display:block;}
    </style>
    </head>
    <body>
    <p><strong>Banner (m2) calculator, quantity & price</strong></p>
    <form name="calculatorForm" action="#">
    <div>

    <p><strong>Banner Size</strong></p>
    <label>Width of banner (m): <input type="text" name="widthBox1" size="6"></label>
    <label>Length of banner (m): <input type ="text" name="lengthBox1" size="6"></label>

    <p><input type= "button" name="calcBtn" value="Calculate" 

    onclick="calc(this.form.areaBox1,this.form.widthBox1.value,this.form.lengthBox1.value)"></p>
    <label>The m2 area for 1 banner is: <input type="text" name="areaBox1" size="12" readonly></label>

        <div class="slider-vertical"></div>
    <div id="purhcaseForm">
         <form id="purchase">
             <br> Item Price: CHF63.50/unit
             <br> Please Select Quantity
             <input type='button' name='subtract' onclick='Total("qty",-1,"total",63.50);' value='-'/>
             <input type='button' name='add' onclick='Total("qty",1,"total",63.50);' value='+'/>
             <input type='text' name='qty' id='qty' readonly=true value="0"/>
             <input type='text' name='total' id='total' value="0" />
          </form>
    </div>


    </div>
    </form>
    </body>
    </html> 

  • #2
    Senior Coder
    Join Date
    Mar 2005
    Location
    Portsmouth UK
    Posts
    4,511
    Thanks
    3
    Thanked 503 Times in 490 Posts
    Code:
    <html>
    <head>
    <title>Banner Cost Calculator</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <script type="text/javascript">
    
    
    
    function calcArea(L,W)
    {return L*W;}
    
    
    function calc(f,W,L){
    var width = parseFloat(W);
    var length = parseFloat(L);
    var area = calcArea (length,width);
    //var squaremeter = calcSquaremeter();
    
    f.value = calcArea(length,width);
    //f.squaremeterBox.value = squaremeter;
    }
    </script>
    
      <script>
    function Total(qty,ud,total,value){
     qty=document.getElementById(qty);
     if (isFinite(value*1)){
      ud>0?qty.value++:qty.value--;
      qty.value=Math.max(qty.value,0);
      document.getElementById(total).value=qty.value*value;
     }
    }
    
    function BannerCost(f,t,b){
     if (f&&t&&isFinite(f*1)&&typeof(b)=='number'){
      t.value=f*b;
     }
    }
      </script>
    <style type="text/css">
    label {display:block;}
    </style>
    </head>
    <body>
    <p><strong>Banner (m2) calculator, quantity & price</strong></p>
    <form name="calculatorForm" action="#">
    <div>
    
    <p><strong>Banner Size</strong></p>
    <label>Width of banner (m): <input type="text" name="widthBox1" size="6"></label>
    <label>Length of banner (m): <input type ="text" name="lengthBox1" size="6"></label>
    
    <p><input type= "button" name="calcBtn" value="Calculate"
    
    onclick="calc(this.form.areaBox1,this.form.widthBox1.value,this.form.lengthBox1.value);BannerCost(this.form.areaBox1.value,this.form.costBox1,2.1);">
    </p>                                                                                                                                     <!-- 2.1 is the cost sqtare meter -->
    <label>The m2 area for 1 banner is: <input type="text" name="areaBox1" size="12" readonly></label>
    <label>The cost for 1 banner is: <input type="text" name="costBox1" size="12" readonly></label>
    
        <div class="slider-vertical"></div>
    <div id="purhcaseForm">
         <form id="purchase">
             <br> Item Price: CHF63.50/unit
             <br> Please Select Quantity
             <input type='button' name='subtract' onclick='Total("qty",-1,"total",this.form.costBox1.value);' value='-'/>
             <input type='button' name='add' onclick='Total("qty",1,"total",this.form.costBox1.value);' value='+'/>
             <input type='text' name='qty' id='qty' readonly=true value="0"/>
             <input type='text' name='total' id='total' value="0" />
          </form>
    </div>
    
    
    </div>
    </form>
    </body>
    </html>
    Vic

    God Loves You and will never love you less.

    http://www.vicsjavascripts.org/Home.htm

    If my post has been useful please donate to http://www.operationsmile.org.uk/

  • #3
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,982
    Thanks
    203
    Thanked 2,536 Times in 2,514 Posts
    See:- *** WARNING: Questions posted here will be deleted! ***.
    This forum which is intended to be used only to
    post a completed (working) script for showcasing/benefit of others.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.


  •  

    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
    •