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
    Nov 2017
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Cant figure out how obtain Total Price before to submit to Paypal..

    Hi every one, I am stuck here. What i want is to submit to paypal link a Total price for bought products in large and small cans...

    After looking up a lot of examples I have come up with this code for my site, posted below.
    I am trying to set up larger 1 litre cans prices and small 500gram cans prices of milk products that must respond to quantities of either sizes to bring about Overall Total Price a client will be required to pay on A WEB PAGE .. according to the total numbers of cans purchased. I am seeking help in making the below code be able to sum up hence obtain a Total Prices for large and small cans in two text boxes (id="select2-basic" and id="select4-basic"), before the Overall Total Price is submitted to the paypal account indicated below; that is, when a client clicks "Buy Now" paypal button on a web page, the Overall Total Price (for large and small cans purchased) must be transmitted to the activated paypal account. I am planning to use the completed form on paypal payments. I have done some research and developed my code to where it is now. But being a new bee, I do not have an idea on how to capture the Total Price for large cans and add it to the Total Price for small cans in order to obtain an Overall Total Price (Lage+Small). The price for smaller cans {in this case denoted as "costs"} is supposed to be half that of the large cans price {int this denoted as "Price"}, as I have indicated. Below is an example of where I have reached but cant crack it to completion. I need your help!

    Code:
    <body> 
    
    <form id="paypal-form" action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post" target="blank">
    
    <fieldset>
    
    <legend>Select a Safari for ePayment</legend>
    
    <label><input type="radio" name="os0" value="Milk Products" checked="checked">: - Select a Product</label>
    <label><input type="radio" name="os0" value="Powdered Milk">: $20 - Powdered milk</label>
    <label><input type="radio" name="os0" value="Homogenous milk">: $30 - Homogenous milk</label>
    <label><input type="radio" name="os0" value="Skimmed milk">: $40 - Skimmed milk</label>
    
    
    <select name="Milk Products" id="select2-basic" class="#"> 
    <option value="Powdered Milk">Powdered Milk</option> 
    <option value="Homogenous milk">Homogenous milk</option>
    <option value="Skimmed milk">Skimmed milk</option>
    
    </br></br>
    <p>Large 1litres Cans:<select name="Largercans" id="select3-basic" value="#">
    <option value="1">1</option>
    <option value="2">2</option>
    <option value="3">3</option>
    
    </br></br>
    <p>Smaller 500gram Cans:<select name="Smallercans" id="select5-basic" value="#">
    <option value="1">1</option>
    <option value="2">2</option>
    <option value="3">3</option>
    
    
    
    
    <input class="span1" readonly type="text" name="Price" id="select2-basic" value="">
    
    <input class="span1" readonly type="text" name="costs" id="select4-basic" value=""></br></br>
    
    
    <script src="https://code.jquery.com/jquery-3.1.1.js"></script>
    
    
    <script>
    
    $(function(){
    
    var prices = {
    'Powdered milk':20,'Homogenous':30,'Skimmed milk':40
    };
    
    
    
    $('#select2-basic, #select3-basic').on('change', function(){
    if(this.name == 'Largercans'){
    $('input[name="Quantity"]').val(+this.value);
    $('input[name="Price"]')
    .val(prices[$('#select2-basic').val()] ? (prices[$('#select2-basic').val()] * this.value) : (1 * this.value));
    };
    });
    }); 
    
    </script>
    
    
    
    <script>
    
    $(function(){
    
    var costs = { 'Powdered milk':10,'Homogenous milk':15,'skimmed milk':20
    
    };
    
    $('#select2-basic, #select5-basic').on('change', function(){
    if (this.name == 'Smallercans'){
    $('input[name="Smallercans"]').val(+this.value);
    $('input[name="costs"]')
    .val(costs[$('#select2-basic').val()] ? (costs[$('#select2-basic').val()] * this.value) : (.5 * this.value)); 
    };
    });
    });
    
    </script>
    
    
    
    <script> // HELP NEEDED HERE!
    
    
    function add(x,y) {
    
    return x+y;
    
    }
    
    add(x,y);
    
    var x = document.getElementById("select2-basic").value;
    
    var y = document.getElementById("select4-basic").value;
    
    // HELP HUMBLY NEEDED..HERE i HAVE NO IDEA ON HOW TO BE ABLE TO ADD THE PRICE FOR LARGER CANS AND SMALLER CANS.. PLEASE FEEL FREE TO MAKE ANY NECESSARY EDITS AND CHANGES TO MAKE CODE WORK.. THX!
    
    </script>
    
    
    
    <input type="hidden" name="item_name" value="Products">
    <input type="hidden" name="tax_rate" value="1.17">
    <input type="hidden" name="shipping" value="4.35">
    <input type="hidden" name="business" value="groceries_sales@mybusiness.com">
    
    **************************************************************************************************** ** 
    
    <input type="hidden" name="cmd" value="_cart">
    <input type="hidden" name="lc" value="US">
    <input type="hidden" name="button_subtype" value="Products">
    <input type="hidden" name="no_note" value="0">
    <input type="hidden" name="add" value="1">
    <input type="hidden" name="bn" value="PP-ShopCartBF:btn_cart_LG.gif:NonHostedGuest">
    <input type="hidden" name="currency_code" value="USD"> 
    <input type="hidden" name="option_index" value="0">
    <input type="hidden" name="on0" value="Type">
    <input type="image" name="submit" src="https://www.paypalobjects.com/webstatic/en_US/i/btn/png/btn_buynow_107x26.png" alt="ePayment">
    <img src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1" alt="">
    
    </fieldset>
    
    </form> 
    
    </html>

    You help is highly needed.

    Thank you.
    Last edited by vinyl-junkie; 11-14-2017 at 07:54 PM. Reason: corrected code tags

  2. #2
    Master Coder sunfighter's Avatar
    Join Date
    Jan 2011
    Location
    Washington
    Posts
    7,474
    Thanks
    31
    Thanked 1,008 Times in 1,005 Posts
    Let first talk coding.
    <select> Needs a closing tag.
    <p> Needs a closing tag.
    and of course you need a </body> tag.
    Why is your JS in the form and not where it belongs?
    Why so many separate scripts? Combine them.
    Why do you use <p> tag to give a SELECT a title???

    Why do you make the three items you sell as radio button selects? - If costumer wants both powdered and homogeneous milk he has to get two bills from paypal.

    You never tell us or the person using your page what the price of a small can is.
    You have two input sections in the form before the 'Buy Now' button with no labels to tell us what they are.
    Last edited by sunfighter; 11-15-2017 at 01:21 AM.
    Evolution - The non-random survival of random variants.
    Physics is actually atoms trying to understand themselves.

  3. Users who have thanked sunfighter for this post:

    Mabobish (11-17-2017)

  4. #3
    New to the CF scene
    Join Date
    Nov 2017
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Hi Sunfighter,

    Thank you for your observation. I am a new bee on javascript and so far I have tried to look through other examples to have the code I have. However it works to an extent of populating prices for large cans and small cans in given the text boxes. Price for smaller cans (var costs) is calculated in second function and it returns as 50% of a large can (product type) price (var prices). This comes from the example I have adopted. therefore I do not know how to combine the scripts, and the reason why I am asking for help.

    I have tried to add some more info as seen below.

    NOTE: For now I am okay with a client getting two bills for two different products. I just need an ice breaker on how I can add the Price value and the costs value to obtain a Total Price that can be submitted to paypal at the end of the code. I hope it is a bit clearer now. Thank you.

    Code:
    <body> 
    
    <form id="paypal-form" action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post" target="blank">
    
    <fieldset>
    
    <legend>Select a Safari for ePayment</legend>
    
    <label><input type="radio" name="os0" value="Milk Products" checked="checked">: - Select a Product</label>
    <label><input type="radio" name="os0" value="Powdered Milk">: $20 - Powdered milk</label>
    <label><input type="radio" name="os0" value="Homogenous milk">: $30 - Homogenous milk</label>
    <label><input type="radio" name="os0" value="Skimmed milk">: $40 - Skimmed milk</label>
    
    
    <select name="Milk Products" id="select2-basic" class="#"> 
    <option value="Powdered Milk">Powdered Milk</option> 
    <option value="Homogenous milk">Homogenous milk</option>
    <option value="Skimmed milk">Skimmed milk</option>
    
    </br></br>
    Large 1litres Cans:<select name="Largercans" id="select3-basic" value="#">
    <option value="1">1</option>
    <option value="2">2</option>
    <option value="3">3</option>
    </select>
    
    
    </br></br>
    Smaller 500gram Cans:<select name="Smallercans" id="select5-basic" value="#">
    <option value="1">1</option>
    <option value="2">2</option>
    <option value="3">3</option>
    
    
    
    
    Large Cans:<input class="span1" readonly type="text" name="Price" id="select2-basic" value="">
    
    Small Cans:<input class="span1" readonly type="text" name="costs" id="select4-basic" value=""></br></br>
    
    
    <script src="https://code.jquery.com/jquery-3.1.1.js"></script>
    
    
    <script>
    
    $(function(){
    
    var prices = {
    'Powdered milk':20,'Homogenous':30,'Skimmed milk':40
    };
    
    
    
    $('#select2-basic, #select3-basic').on('change', function(){
    if(this.name == 'Largercans'){
    $('input[name="Quantity"]').val(+this.value);
    $('input[name="Price"]')
    .val(prices[$('#select2-basic').val()] ? (prices[$('#select2-basic').val()] * this.value) : (1 * this.value));
    };
    });
    }); 
    
    </script>
    
    
    
    <script>
    
    $(function(){
    
    var costs = { 'Powdered milk':10,'Homogenous milk':15,'skimmed milk':20
    
    };
    
    $('#select2-basic, #select5-basic').on('change', function(){
    if (this.name == 'Smallercans'){
    $('input[name="Smallercans"]').val(+this.value);
    $('input[name="costs"]')
    .val(costs[$('#select2-basic').val()] ? (costs[$('#select2-basic').val()] * this.value) : (.5 * this.value)); 
    };
    });
    });
    
    </script>
    
    
    
    <script> // HELP NEEDED HERE!
    
    
    function add(x,y) {
    
    return x+y;
    
    }
    
    add(x,y);
    
    var x = document.getElementById("select2-basic").value;
    
    var y = document.getElementById("select4-basic").value;
    
    // HELP HUMBLY NEEDED..HERE i HAVE NO IDEA ON HOW TO BE ABLE TO ADD THE PRICE FOR LARGER CANS AND SMALLER CANS.. PLEASE FEEL FREE TO MAKE ANY NECESSARY EDITS AND CHANGES TO MAKE CODE WORK.. THX!
    
    </script>
    
    
    
    <input type="hidden" name="item_name" value="Products">
    <input type="hidden" name="tax_rate" value="1.17">
    <input type="hidden" name="shipping" value="4.35">
    <input type="hidden" name="business" value="groceries_sales@mybusiness.com">
    
    **************************************************************************************************** ** 
    
    <input type="hidden" name="cmd" value="_cart">
    <input type="hidden" name="lc" value="US">
    <input type="hidden" name="button_subtype" value="Products">
    <input type="hidden" name="no_note" value="0">
    <input type="hidden" name="add" value="1">
    <input type="hidden" name="bn" value="PP-ShopCartBF:btn_cart_LG.gif:NonHostedGuest">
    <input type="hidden" name="currency_code" value="USD"> 
    <input type="hidden" name="option_index" value="0">
    <input type="hidden" name="on0" value="Type">
    <input type="image" name="submit" src="https://www.paypalobjects.com/webstatic/en_US/i/btn/png/btn_buynow_107x26.png" alt="ePayment">
    <img src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1" alt="">
    
    </fieldset>
    
    </form>
    
    </body> 
    
    </html>
    Last edited by vinyl-junkie; 11-18-2017 at 01:53 AM. Reason: corrected code tags


 

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
  •