Concatenate radio and checkbox data into PayPal.



All this simple JavaScript (JS) plugin does is to accept the value from checkboxes and radio buttons along with any pricing information, or description data, and concatenate it into various PayPal fields.

We start with the output of the PayPal button factory and make a few changes. Then the JS processes the FORM and adjusts the fields. <view source>) to see what was done.

  • Copy the JS from this example and paste it into your page within the <head> section, like is done on this page. Only one copy of the JS is needed for any page.
  • If you want a view-cart button somewhere on the page you must copy the view FORM from my page and insert it into your page right after the <body... statement like I have done here. You will need to change the business value, or course. More info
  • Go into every FORM that can place an order and add these things...
    • A new named element called baseamt to hold the base amount of the item.
    • A new named element called basedes to hold the base description of this item.
    • If you are going to use any of the option fields, then you must create a base description for them, like with baseamt and basedes, above. Add fields named baseon0, baseos0, baseon1 and baseos1 to the items in the FORM for each item in your site.
    • If you are going to modify shipping values then you must include shipping and shipping2 variables in the FORM.
    • An event handler (EH) to the "add" button or, as is done here, an onsubmit EH to the FORM element. This EH determines whether or not the FORM will be submitted to PayPal. It has a simple validation routine that makes sure at least something was entered into all the fields.
    • An optional text field named tot where the item cost is displayed if you include EHs on all the items that modify price. In this case the base price of the tot variable must be the default settings of the items before any price adjustment is made. Right-click to see how I did it on this page.
    • Fields (with flaged names, perhaps) so the user can input his values. The flag is the last two characters of the name.

      	1a = 1st option field name area (50 chars).
      	1b = 1st option field data area (200 chars).
      	2a = 2nd option field name area (50 chars).
      	2b = 2nd option field data area (200 chars).
      	3i = item_number field data area (127 chars).
      	.. (Anything else, description area - 127 chars.)
      

  • There are single token, and three-token flags that may be used in the value field of the options.

    • "#" to indicate that an item number follows.
    • "@" to indicate that a price value follows.
    • "+" to indicate that a price increment follows.
    • "%" to indicate that a price percent change follows.
    • "s1=" indicates a shipping value follows.
    • "'s2=" indicates a shipping2 value follows.
    • It is not obvious, but negative amounts are allowed. The first characters are a flag value (has special significance to parsing), but after that you may input any valid nunmber. -1 is a valid number, so "+-1.50" is perfectly legal.

    Here is an example of what you may put into the value of an option field of a select...

    <option value="Item #A1234 s1=10 s2=8.50 @25.00">...</option>
    		

    Setting shipping is a little tricky, in that if you use it in any value field of a select, then you must use it in every value field, even if it is set to zero. Also, don't forget to include the hidden shipping and shipping2 fields in your FORM so they can be stuffed.

    It doesn't make much sense to use item number or shipping in checkboxes, but it does in radio buttons...

    We are getting a little more sophisticated here by adding an extra argument to ReadForm so the text validation is only done upon FORM submission.



    Base Item @10.00, blah, blah.

    Check box 1 (+2.00).
    Check box 2 (+3.00).

    Rad 1 (+0.50).
    Rad 2 (+0.75).
    Rad 3 (+0.95).

      Item Total >  




    Back To Main Page



    info@capleswebdev.com