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

    Need help with javascript controlling functions with Paypal form

    I am trying to do a custom add to cart to use with paypal and need to utilize javascript to achieve inserting some code or a weight value per the paypal forms' options choice. Here is my dilemma, All of my items have multiple weights, for instance the below example called Aqua Max 100 comes in .5lbs, 1.5lbs., 10lbs., 20lbs., and 50lbs. Paypal allows you to enter weight but it's one weight per item and I would have to create 5 Paypal buttons just for this one item to calculate the different weights per zip code. I need help making javascript insert the following code within the paypal forms' code upon option select before clicking submit?

    <input type="hidden" name="weight" value=".5">
    <input type="hidden" name="weight_unit" value="lbs">

    <input type="hidden" name="weight" value="1.5">
    <input type="hidden" name="weight_unit" value="lbs">

    <input type="hidden" name="weight" value="10
    <input type="hidden" name="weight_unit" value="lbs">

    <input type="hidden" name="weight" value="20
    <input type="hidden" name="weight_unit" value="lbs">

    <input type="hidden" name="weight" value="50
    <input type="hidden" name="weight_unit" value="lbs">

    The code I came up with is wrong as I'm getting an error but I was originally trying to make it enter a weight using a hidden fillable number and without any real javascript training, just alot of googling but I think I'm pretty close. Please take a look at the code I've came up with so far and maybe point me in the correct direction:

    <html>
    <body>
    <form target="paypal" action="https://www.paypal.com/cgi-bin/webscr"
    method="post">
    <input type="hidden" name="cmd" value="_cart"> <input type="hidden"
    name="business" value="test@test.com">
    <input type="hidden" name="currency_code" value="USD"> <input type='hidden'text'
    name='amt' id='amt' value="0.00"/>
    <table>
    <tr>
    <td>
    <input type="text" name="on0" value="Aqua Max 100">Aqua Max 100</td></tr>
    <tr><td>
    <select name="os0" onChange="getamt()">
    <option value="select">Please Select</option>
    <option value="1/2 lb.">1/2 lb. $3.99 USD</option>
    <option value="1 - 1/2 lbs">1 - 1/2 lbs $7.59 USD</option>
    <option value="10 lbs.">10 lbs. $25.80 USD</option>
    <option value="20 lbs.">20 lbs. $42.75 USD</option>
    <option value="50 lbs.">50 lbs. $86.20 USD</option>
    </select></td></tr> </table>
    <script type="text/javascript"> function getamt() {
    var sh=0;
    var choice = document.getElementById("os0").selectedIndex;
    if (choice == 0)
    { sh=0; }
    if (choice == 1)
    { sh=.5; }
    if (choice == 2)
    { sh=1.5; }
    if (choice == 3)
    { sh=10; }
    if (choice == 4)
    { sh=20 }
    if (choice == 5)
    { sh=50.00; }
    document.getElementById("on0").value=sh;
    }
    </script>
    <input type="image" src="https://images.paypal.com/images/sc-but-03.gif"
    border="0" name="submit" alt="PayPal - The safer, easier way to pay online!" /> <img
    alt="" border="0"
    src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1"
    height="1">
    </form>
    </body>
    </html>

  • #2
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,628
    Thanks
    0
    Thanked 648 Times in 638 Posts
    So what do you expect to happen for those who visit your page with JavaScript disabled or unavailable?

    What about those who override your javaScript to insert a lower price than the one that belongs to the weight they select?

    The only way to get it to work for everyone will be a server side solution and will not require any JavaScript.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #3
    New to the CF scene
    Join Date
    Mar 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Very good questions.
    First answer regarding server side solution: I was new with website design a few years back and I purchased what used to be called Sitebuilder now called Homestead through Intuit Quickbooks because they are who I chose to use for all of my financials and they offered this solution to me. Unfortunately this is an online website generator (generic) which they do not allow for any software to be installed. I do have the option though to insert custom HTML snippets with in box and drag it where I want it on the website. When my hosting is up in 2014 that I already paid for, non-refundable, I purchased a 5 year option being proactive, I will redesign a new website on a server that I have more control over.

    Second answer: Since the Javascript will only be controlling the weight of the option and not the unit price, worst case scenario it's only going to benefit them by getting free shipping and a nice thank you from me. I'm selling fish food not high end stuf electronics, lol.

    Third answer: I will display Javascript must be enabled to add items to cart and provide a link on how to do this.
    Last edited by picks-it; 03-28-2012 at 09:46 PM. Reason: Forgot to answer second question

  • #4
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,628
    Thanks
    0
    Thanked 648 Times in 638 Posts
    Quote Originally Posted by picks-it View Post
    Third answer: I will display Javascript must be enabled to add items to cart and provide a link on how to do this.
    So what instructions will you provide for those using browsers that have no JavaScript support at all and who don't have the option of using a browser that has JavaScript?

    Web pages should always work without JavaScript - particularly those where you are selling something.

    Anyone with JavaScript turned off usually has it that way for a reason and even where they could turn it on they will generally leave your site and go elsewhere to make their purchase rather than turn it on in order to get your site to work.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #5
    New to the CF scene
    Join Date
    Mar 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Well for those who do not have Javascript installed I would provide them a link to download Java and phone number to call and purchase over the phone if they prefer not to install Java like:

    No Javascript, get it <a href="http://www.java.com/">here</a> or call (xxx) xxx-xxxx to place your order.

    ...and for those that do have Javascript but for some reason it's disabled and they want to enable it, it would say something like:

    Having problems, already have Javascript installed make sure it's enabled <a href="http://enable-javascript.com/">click here</a> or check to see if you have the <a href="http://www.java.com/">Java latest version</a>.

  • #6
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,628
    Thanks
    0
    Thanked 648 Times in 638 Posts
    Java has almost nothing in common with JavaScript except that they are both languages that you can write computer code with.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.


  •  

    Posting Permissions

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