hopefully easy programming question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Andrea Chen

    hopefully easy programming question

    I'm new to this (2 days new) so please bear with me.
    I want have a form & button working with a paypal order so that when
    the user puts in the order quantity on my page, the javascript selects
    the correct price based on quantity and sends those 2 numbers to
    paypal.

    I have no idea how to do this. I don't know if it should go in the
    ShowPRice function or if it should be done in a form. Would someone
    help me?

    What I have written so far:

    <html>
    <head>
    <script language="javas cript" type="text/javascript">
    <!--
    function CalculatePrice( NumOrdered)
    {
    if (NumOrdered>=6 && NumOrdered<=10)
    {var ItemPrice = 5.00 }
    else if (NumOrdered >=11 && NumOrdered<=25)
    {var ItemPrice = 4.50 }
    else if (NumOrdered >=26 && NumOrdered<=80)
    {var ItemPrice = 4.00 }
    else if (NumOrdered> 80)
    {var ItemPrice = 3.50 }
    else if (NumOrdered< 6)
    {alert("Minimum wholesale order is 6") ;
    var ItemPrice = 5.00 }
    else
    {alert("You did not enter a number!");
    var ItemPrice = 5.00}
    return ItemPrice ;
    }

    function ShowPrice(NumOr dered)
    {
    var FinalPrice=Calc ulatePrice(NumO rdered);
    alert("Price per unit: "+FinalPric e)
    }

    // -->
    </script>
    </head>

    <body>

    <***** now this form fm2a works very nicely and shows me the correct
    <***** price
    <form name="fm2a">
    Enter quantity :
    <input type="text" name="quantity" >
    <input type="button" name="dis" value="Add to Cart"
    onClick='ShowPr ice(document.fm 2a.quantity.val ue)'>
    </form>


    <***** But what I really want is the button to do place a paypal
    order,
    <***** inserting the quantity ordered and the correct price. What
    I've
    <***** done here does not work.
    <form name="submit" target="paypal"
    action="https://www.paypal.com/cgi-bin/webscr" method="post">
    Enter quantity :
    <input type="text" name="quantity" >
    <input type="button" name="dis" value="Add to Cart"
    onClick='ShowPr ice(document.su bmit.quantity.v alue)'>
    <input type="hidden" name="add" value=NumOrdere d>
    <input type="hidden" name="cmd" value="_cart">
    <input type="hidden" name="business" value="paypal@m ystore.com">
    <input type="hidden" name="item_name " value="Wholesal e item">
    <input type="hidden" name="item_numb er" value="WRTH">
    <input type="hidden" name="amount" value=FinalPric e>
    <input type="hidden" name="no_note" value="1">
    <input type="hidden" name="currency_ code" value="USD">
    <input type="hidden" name="lc" value="US">
    </form>
    </body>
    </html>
  • Andrew Thompson

    #2
    Re: hopefully easy programming question

    On 26 May 2004 17:43:45 -0700, Andrea Chen wrote:
    [color=blue]
    > I want have a form & button working with a paypal order[/color]

    AFAIR, you do that at the PayPal end by setting up
    different links to go to. You could then choose which
    link with JS, or simply list the different products as
    separate links..

    --
    Andrew Thompson
    http://www.PhySci.org/ Open-source software suite
    http://www.PhySci.org/codes/ Web & IT Help
    http://www.1point1C.org/ Science & Technology

    Comment

    • Andrea Chen

      #3
      Re: hopefully easy programming question

      Andrew Thompson <SeeMySites@www .invalid> wrote in message news:<1sqxem991 hpyq.1n8cdygf5c n3p.dlg@40tude. net>...[color=blue]
      > On 26 May 2004 17:43:45 -0700, Andrea Chen wrote:
      >[color=green]
      > > I want have a form & button working with a paypal order[/color]
      >
      > AFAIR, you do that at the PayPal end by setting up
      > different links to go to. You could then choose which
      > link with JS, or simply list the different products as
      > separate links..[/color]

      They're not different products, just different quantities of the same
      product. I think I need to have a Paypal store to do that (which I
      don't...). I'll look into it, though.

      Comment

      • Charles Crume

        #4
        Re: hopefully easy programming question


        "Andrea Chen" <dirthawker@hot mail.com> wrote in message
        news:b9bb5d98.0 405271015.52097 6c6@posting.goo gle.com...[color=blue]
        > Andrew Thompson <SeeMySites@www .invalid> wrote in message[/color]
        news:<1sqxem991 hpyq.1n8cdygf5c n3p.dlg@40tude. net>...[color=blue][color=green]
        > > On 26 May 2004 17:43:45 -0700, Andrea Chen wrote:
        > >[color=darkred]
        > > > I want have a form & button working with a paypal order[/color]
        > >
        > > AFAIR, you do that at the PayPal end by setting up
        > > different links to go to. You could then choose which
        > > link with JS, or simply list the different products as
        > > separate links..[/color]
        >
        > They're not different products, just different quantities of the same
        > product. I think I need to have a Paypal store to do that (which I
        > don't...). I'll look into it, though.[/color]

        You don't have to do anything of the sort. When the user clicks on the link,
        the PayPal shopping cart page appears andyour customer can change the
        *uantity field*there.

        go to www.charlescrumesoftware.com/dms.htm and click on one of the "Add to
        Cart" buttons to see this.

        HTH.

        Charles...



        ---
        Outgoing mail is certified Virus Free.
        Checked by AVG anti-virus system (http://www.grisoft.com).
        Version: 6.0.691 / Virus Database: 452 - Release Date: 5/26/04


        Comment

        • Lee

          #5
          Re: hopefully easy programming question

          Andrea Chen said:[color=blue]
          >
          >I'm new to this (2 days new) so please bear with me.
          >I want have a form & button working with a paypal order so that when
          >the user puts in the order quantity on my page, the javascript selects
          >the correct price based on quantity and sends those 2 numbers to
          >paypal.
          >
          >I have no idea how to do this. I don't know if it should go in the
          >ShowPRice function or if it should be done in a form. Would someone
          >help me?[/color]



          I don't know much about PayPal. Maybe I'm wrong, but
          unless you know that I'm wrong, you should reconsider
          using client-side Javascript to compute your prices and
          send the result off to be billed. There are a lot of us
          out here who can read your code and make changes to it on
          the fly so that the function sends PayPal whatever price
          we happen to feel like paying.

          Even if you're not actually committed to sell at the price
          that PayPal receives, I'll bet that it's going to cost you
          time and trouble (at least) to back out of the transaction.


          Now that you know that you shouldn't do this, here's how:
          [color=blue]
          > <input type="hidden" name="amount" value=FinalPric e>[/color]

          Apparently you were hoping that this line would set the
          value of FinalPrice at the time of form submission. Since
          that's an HTML line, it actually sets the value at the time
          that the form is first displayed, and since HTML doesn't
          know anything about variables, it sets the value to "FinalPrice ".

          The correct way to have your function set the value of the
          hidden form field named "amount" is:

          function ShowPrice(NumOr dered)
          {
          var FinalPrice=Calc ulatePrice(NumO rdered);
          document.forms["submit"].elements["amount"].value=FinalPri ce;
          }

          Note that this doesn't submit the form for you.

          Comment

          • Andrea Chen

            #6
            Re: hopefully easy programming question

            "Charles Crume" <cc@charlescrum esoftware.com> wrote in message news:<gArtc.708 $m8.61@fe1.colu mbus.rr.com>...[color=blue]
            > You don't have to do anything of the sort. When the user clicks on the link,
            > the PayPal shopping cart page appears andyour customer can change the
            > *uantity field*there.[/color]

            Ummm....Charles ... I think you may have missed the point behind my
            dipping into javascript. The *price* *changes* according to the
            quantity ordered.

            -andrea-

            Comment

            • Andrea Chen

              #7
              Re: hopefully easy programming question

              Lee <REM0VElbspamtr ap@cox.net> wrote in message news:<c95hn802b 66@drn.newsguy. com>...[color=blue]
              > I don't know much about PayPal. Maybe I'm wrong, but
              > unless you know that I'm wrong, you should reconsider
              > using client-side Javascript to compute your prices and
              > send the result off to be billed. There are a lot of us
              > out here who can read your code and make changes to it on
              > the fly so that the function sends PayPal whatever price
              > we happen to feel like paying.[/color]

              I have in fact tried it just to see if it could be done, and it can.
              Copy the page source, tweak it and run it. Doesn't matter html or
              javascript, if the prices are in the page source, anyone can mess with
              it.
              [color=blue]
              > The correct way to have your function set the value of the
              > hidden form field named "amount" is:
              >
              > function ShowPrice(NumOr dered)
              > {
              > var FinalPrice=Calc ulatePrice(NumO rdered);
              > document.forms["submit"].elements["amount"].value=FinalPri ce;
              > }
              >
              > Note that this doesn't submit the form for you.[/color]

              I see. Thank you very much. I think though as you and Andrew said,
              it's probably safer to have the prices locked somewhere else.

              -andrea-

              Comment

              • Thomas 'PointedEars' Lahn

                #8
                Re: hopefully easy programming question

                Andrea Chen wrote:
                [color=blue]
                > Lee [...] wrote [...][color=green]
                >> I don't know much about PayPal. Maybe I'm wrong, but
                >> unless you know that I'm wrong, you should reconsider
                >> using client-side Javascript to compute your prices and
                >> send the result off to be billed. There are a lot of us
                >> out here who can read your code and make changes to it on
                >> the fly so that the function sends PayPal whatever price
                >> we happen to feel like paying.[/color]
                >
                > I have in fact tried it just to see if it could be done, and it can.
                > Copy the page source, tweak it and run it. Doesn't matter html or
                > javascript, if the prices are in the page source, anyone can mess with
                > it.[/color]

                It is much more simple. Consider something like

                javascript:aler t(document.form s[0].elements['foo'].value = 0.0042);

                typed in the Location Bar ;-)


                PointedEars

                Comment

                Working...