www.webdeveloper.com
Results 1 to 6 of 6

Thread: CheckBox with Quantity *Help*

  1. #1
    Join Date
    Sep 2013
    Posts
    3

    Question CheckBox with Quantity *Help*

    Hi there

    Im actualy kind of new in this and im trying to make this chekbox with quantity so i can send it to paypall.
    But with these codes its not doing it like it should.
    i want my clients to check the box(es) fill in the quantity and then pay.
    Çan anybody tell me what i am doing wrong? or show me a better code

    here are the codes

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>

    <title>Button Example Code</title>

    <!-- START META TAG SECTION -->
    <meta charset="utf-8">
    <meta http-equiv="Content-Type" content="text/html;charset=utf-8">
    <meta http-equiv="Content-Language" content="en">
    <!-- END META TAG SECTION -->


    <!-- Start of Script -->
    <SCRIPT LANGUAGE="JavaScript"><!--

    var count=1;

    function codename() {
    count=1;

    document.formname.item_name_1.value='';
    document.formname.item_name_2.value='';
    document.formname.item_name_3.value='';
    document.formname.item_name_4.value='';
    document.formname.item_name_5.value='';
    document.formname.amount_1.value='';
    document.formname.amount_2.value='';
    document.formname.amount_3.value='';
    document.formname.amount_4.value='';
    document.formname.amount_5.value='';
    document.formname.quantity_1.value='';
    document.formname.quantity_2.value='';
    document.formname.quantity_3.value='';
    document.formname.quantity_4.value='';
    document.formname.quantity_5.value='';

    if(document.formname.item1.checked)
    {
    document.formname.item_name_1.value = "Numb 1";
    document.formname.amount_1.value = "1.00"*"quantity_1";
    document.formname.quantity_1.value='';
    count=count+1;
    }
    if(document.formname.item2.checked)
    {
    if(count==2){
    document.formname.item_name_2.value = "Numb 2";
    document.formname.amount_2.value = "1.00";
    document.formname.quantity_2.value='';
    count=count+1;
    }
    if(count==1){
    document.formname.item_name_1.value = "Numb 2";
    document.formname.amount_1.value = "1.00";
    document.formname.quantity_1.value='';
    count=count+1;
    }
    }
    if(document.formname.item3.checked)
    {

    if(count==3){
    document.formname.item_name_3.value = "Numb 3";
    document.formname.amount_3.value = "1.00";
    document.formname.quantity_3.value='';
    count=count+1;
    }
    if(count==2){
    document.formname.item_name_2.value = "Numb 3";
    document.formname.amount_2.value = "1.00";
    document.formname.quantity_2.value='';
    count=count+1;
    }
    if(count==1){
    document.formname.item_name_1.value = "Numb 3";
    document.formname.amount_1.value = "1.00";
    document.formname.quantity_1.value='';
    count=count+1;
    }
    }
    if(document.formname.item4.checked)
    {
    if(count==4){
    document.formname.item_name_4.value = "Numb 4";
    document.formname.amount_4.value = "1.00";
    document.formname.quantity_4.value='';
    count=count+1;
    }
    if(count==3){
    document.formname.item_name_3.value = "Numb 4";
    document.formname.amount_3.value = "1.00";
    document.formname.quantity_3.value='';
    count=count+1;
    }
    if(count==2){
    document.formname.item_name_2.value = "Numb 4";
    document.formname.amount_2.value = "1.00";
    document.formname.quantity_2.value='';
    count=count+1;
    }
    if(count==1){
    document.formname.item_name_1.value = "Numb 4";
    document.formname.amount_1.value = "1.00";
    document.formname.quantity_1.value='';
    count=count+1;
    }
    }

    if(document.formname.item5.checked)
    {
    if(count==5){
    document.formname.item_name_5.value = "Numb 5";
    document.formname.amount_5.value = "1.00";
    document.formname.quantity_5.value='';
    count=count+1;
    }

    if(count==4){
    document.formname.item_name_4.value = "Numb 5";
    document.formname.amount_4.value = "1.00";
    document.formname.quantity_4.value='';
    count=count+1;
    }
    if(count==3){
    document.formname.item_name_3.value = "Numb 5";
    document.formname.amount_3.value = "1.00";
    document.formname.quantity_3.value='';
    count=count+1;
    }
    if(count==2){
    document.formname.item_name_2.value = "Numb 5";
    document.formname.amount_2.value = "1.00";
    document.formname.quantity_2.value='';
    count=count+1;
    }
    if(count==1){
    document.formname.item_name_1.value = "Numb 5";
    document.formname.amount_1.value = "1.00";
    document.formname.quantity_1.value='';
    count=count+1;
    }
    }

    }
    //-->
    </SCRIPT>
    <!-- End of Script -->



    </head>

    <body>

    <!-- START SAMPLE CODE SECTION -->


    <!-- PARAGRAPH 1 -->


    <br><br>
    Please Choose Your Number(s)

    <br><br>

    <form name="formname" target="paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post">
    <!-- If using a Business or Company Logo Graphic, include the "cpp_header_image" variable in your View Cart code. -->
    <input type="hidden" name="cpp_header_image" value="https://www.yourwebsite.com/logo.jpg">
    <!-- Replace "business" value with your PayPal Email Address or Account ID -->
    <input type="hidden" name="business" value="chachileibah@gmail.com">
    <input type="hidden" name="cmd" value="_cart">
    <input type="hidden" name="upload" value="1">
    <input type="hidden" name="currency_code" value="USD">
    <input type="hidden" name="lc" value="US">
    <!-- Replace value with the web page you want the customer to return to after a successful transaction -->
    <input type="hidden" name="return" value="http://www.yourwebsite.com/ThankYou.html">
    <!-- Replace value with the web page you want the customer to return to after item cancellation -->
    <input type="hidden" name="cancel_return" value="http://www.yourwebsite.com/Cancel.html">
    <input type="hidden" name="button_subtype" value="products">
    <input type="hidden" name="no_note" value="0">
    <input type="hidden" name="cn" value="Add special instructions to the seller:">
    <input type="hidden" name="bn" value="PP-ShopCartBF:btn_paynowCC_LG.gif:NonHosted">
    <input type="hidden" name="amount_1">
    <input type="hidden" name="amount_2">
    <input type="hidden" name="amount_3">
    <input type="hidden" name="amount_4">
    <input type="hidden" name="amount_5">
    <input type="hidden" name="item_name_1">
    <input type="hidden" name="item_name_2">
    <input type="hidden" name="item_name_3">
    <input type="hidden" name="item_name_4">
    <input type="hidden" name="item_name_5">
    <input type="hidden" name="quantity_1">
    <input type="hidden" name="quantity_2">
    <input type="hidden" name="quantity_3">
    <input type="hidden" name="quantity_4">
    <input type="hidden" name="quantity_5">

    <table>
    <tr>
    <td>CheckBox&nbsp;&nbsp;</td>
    <td>Number&nbsp;&nbsp;</td>
    <td>Price&nbsp;&nbsp;</td>
    <td>Quantity&nbsp;&nbsp;</td>
    </tr>
    <tr>
    <td>&nbsp;&nbsp;<input type="checkbox" name="item1" value="Item 1"></td>
    <td># 1&nbsp;&nbsp;</td>
    <td>$1.00</td>
    <td><input type="text" name="quantity_1" value=""/></td>
    </tr>
    <tr>
    <td>&nbsp;&nbsp;<input type="checkbox" name="item2" value="Item 2"></td>
    <td># 2&nbsp;&nbsp;</td>
    <td>$1.00</td>
    <td><input type="text" name="quantity_2" value=""/></td>
    </tr>
    <tr>
    <td>&nbsp;&nbsp;<input type="checkbox" name="item3" value="Item 3"></td>
    <td># 3&nbsp;&nbsp;</td>
    <td>$1.00</td>
    <td><input type="text" name="quantity_3" value=""/></td>
    </tr>
    <tr>
    <td>&nbsp;&nbsp;<input type="checkbox" name="item4" value="Item 4"></td>
    <td># 4&nbsp;&nbsp;</td>
    <td>$1.00</td>
    <td><input type="text" name="quantity_4" value=""/></td>
    </tr>
    <tr>
    <td>&nbsp;&nbsp;<input type="checkbox" name="item5" value="Item 5"></td>
    <td># 5&nbsp;&nbsp;</td>
    <td>$1.00</td>
    <td><input type="text" name="quantity_5" value=""/></td>
    </tr>
    </table>


    <br>

    <input type="button" value="Reset Form" onClick="this.form.reset()">

    <br><br>

    <input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_paynowCC_LG.gif" border="0" name="submit" onclick="codename()" alt="Make payments with PayPal - it's fast, free and secure!">
    <img alt="" border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1">
    </form>


    <!-- END BUTTON EXAMPLES -->



    <!-- END SAMPLE CODE SECTION -->

    <br><br><br><br>
    <hr align="left" width="50%" noshade>
    <br><br>
    NOTES:
    <br>



    </body>
    </html>

  2. #2
    Join Date
    Dec 2005
    Location
    FL
    Posts
    7,444
    So that I don't accidently submit an order with many more items than I wish to have,
    can you specify what it is that is not working to your satisfaction?
    Where does the error appear to be or what happens when the error occurs?
    Have you evaluated the error console in FF or Chrome browsers?
    Is it a display problem or a submission problem?

    BTW: You should enclose your program between [ code] and [ /code] tags (without the spaces) to make it easier to
    see formatting. Plus it makes it easier to copy, test/debug your code.

  3. #3
    Join Date
    May 2006
    Location
    Somewhere behind your screen
    Posts
    1,674
    Quote Originally Posted by JMRKER View Post
    So that I don't accidently submit an order with many more items than I wish to have...
    good one

    the error that occurs is

    Error Detected
    Error Message

    The link you have used to enter the PayPal system contains an incorrectly formatted item amount.
    it is shown in a new opened window which url is the form action value
    Last edited by Padonak; 09-21-2013 at 06:53 AM.

  4. #4
    Join Date
    Sep 2013
    Posts
    3
    it is a submision problem, for example when i check "#1" (witch is the first checkbox) and set the quantity it will submit corectly,
    but when i check the second one without checking the first one and fill the quantity of the seconde one it wont submit with the quantity in the chekout

  5. #5
    Join Date
    Mar 2007
    Location
    localhost
    Posts
    2,519
    When you have your user click your submit button, the function called instantly encounters this batch of javascript
    Code:
    document.formname.item_name_1.value='';
    document.formname.item_name_2.value='';
    document.formname.item_name_3.value='';
    document.formname.item_name_4.value='';
    document.formname.item_name_5.value='';
    document.formname.amount_1.value='';
    document.formname.amount_2.value='';
    document.formname.amount_3.value='';
    document.formname.amount_4.value='';
    document.formname.amount_5.value='';
    document.formname.quantity_1.value='';
    document.formname.quantity_2.value='';
    document.formname.quantity_3.value='';
    document.formname.quantity_4.value='';
    document.formname.quantity_5.value='';
    Which if I am not mistaken is clearing any data contained in the form.

    Then this block of code here
    Code:
    if(document.formname.item1.checked)
    {
    document.formname.item_name_1.value = "Numb 1";
    document.formname.amount_1.value = "1.00"*"quantity_1";
    document.formname.quantity_1.value='';
    count=count+1;
    }
    it has an invalid operator trying to update an amount field.

    I would make a suggestion that you look at your script carefully and try a different approach, sometime throwing out what you have is what it takes to make a fresh start.

    Consider some of the following.

    1. indentation for code readability
    2. simplify the script so that your javascript cart updates a smaller number of data fields, effectively reducing the form to single fields
    3. split the script you have in to smaller reusable functions

    Obsevations
    You have check boxes, they serve little purpose and you could do a simpler script that looks at if a quantity has been added to the quantity fields and check if they are positive values before calculation of the basket on click of the paypal button.

    I have had a bit of a play with the code and only Item 1 ever shows in the paypal page

    Suggest that you split the paypap form and put fields in the cart in to its own form then have a function that on submit checks the form elements, tallies up what is needed, push the data in to the paypal form and then either automatically submlit the paypal form or prompt the user to click the paypal button.
    Yes, I know I'm about as subtle as being hit by a bus..(\\.\ Aug08)
    Yep... I say it like I see it, even if it is like a baseball bat in the nutz... (\\.\ Aug08)
    I want to leave this world the same way I came into it, Screaming, Incontinent & No memory!
    I laughed that hard I burst my colostomy bag... (\\.\ May03)
    Life for some is like a car accident... Mine is like a motorway pile up...

    Problems with Vista? :: Getting Cryptic wid it. :: The 'C' word! :: Whois?

  6. #6
    Join Date
    Sep 2013
    Posts
    3
    ok thx very much
    i will try

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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
  •  
HTML5 Development Center



Recent Articles