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 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Oct 2011
    Posts
    9
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Link input with a form?

    Hello Codingforums, yet again I desire some help to my coding, this time regarding a paypal button.

    I'm working on a local project of mine in which I wish to let my costumers type the amount of quantities for a product they wish into a text box and then want it to automatically edit the amount of quantities on the paypal page. This works when I have the input inside the form, but due to my template I wish to have my quantity text box outside the "form" code of the paypal button but still want it to connect so that it changes. Let me explain with some code

    This is the working code for which i can enter the amount of quantities into a text box and it will automatically change it on the paypal page as well.
    Code:
    <div id="payment" style="margin-top:10px;">
    	<form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_blank">
    	<input type="hidden" name="cmd" value="_s-xclick">
    	
    	<input type="TEXT" name="quantity" value="1">
    	
    	<input type="hidden" name="hosted_button_id" value="C5P9LBML2FSC6">
    	<input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_paynow_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
    	<img alt="" border="0" src="https://www.paypalobjects.com/da_DK/i/scr/pixel.gif" width="1" height="1">
    	</form>
    </div>
    This is what I want it to do, I want to be able to put the input of the quantities text box onto another div and still be able to change the amount of quantities on paypal. (Doesn't change the amount of quantities when clicked on button)
    Code:
    <div id="anotherdiv">
    	<input type="TEXT" name="quantity" value="1">
    </div>
    
    <div id="payment" style="margin-top:10px;">
    	<form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_blank">
    	<input type="hidden" name="cmd" value="_s-xclick">
    	<input type="hidden" name="hosted_button_id" value="C5P9LBML2FSC6">
    	<input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_paynow_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
    	<img alt="" border="0" src="https://www.paypalobjects.com/da_DK/i/scr/pixel.gif" width="1" height="1">
    	</form>
    </div>
    Thx in advance
    - rec0il

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    26,576
    Thanks
    80
    Thanked 4,497 Times in 4,461 Posts
    This is a JavaScript question, not an HTML question.

    Pretty simple.
    Code:
    <div id="anotherdiv">
        <form id="getQty">
    	<input type="text" name="quantity" value="1">
        </form>
    </div>
    
    <div id="payment" style="margin-top:10px;">
    	<form id="PPform" action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_blank">
            <input type="hidden" name="quantity" value="1">
    	<input type="hidden" name="cmd" value="_s-xclick">
    	<input type="hidden" name="hosted_button_id" value="C5P9LBML2FSC6">
    	<input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_paynow_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
    	<img alt="" border="0" src="https://www.paypalobjects.com/da_DK/i/scr/pixel.gif" width="1" height="1">
    	</form>
    </div>
    
    <script type="text/javascript">
    document.getElementById("getQty").quantity.onchange = function( ) 
    {
        var qty = parseInt(this.value);
        if ( qty < 1 || qty > 100 ) { qty = 1; } /* if qty out of range, force it to 1 */
        this.value = qty; // put it back in place as an integer, just in case
        document.getElementById("PPform").quantity = qty; // clone to the PayPal form
    }
    </script>
    You can change if ( qty < 1 || qty > 100 ) to whatever range you want to allow, of course

    Code is untested, but it looks right to me.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #3
    New to the CF scene
    Join Date
    Aug 2014
    Location
    Indaia, Dlhi
    Posts
    7
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Unfortunately, hyperlinks and form input field values exist in two different worlds within the web page. You might be able to do what you want with Javascript. It seems like a kind of unnatural thing to do, however. For one thing, people never expect clicking a link to submit a form. Right off, defying user expectations, tells you something is wrong.

  • #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    26,576
    Thanks
    80
    Thanked 4,497 Times in 4,461 Posts
    "helendavis" and Elly1: What in the name of beelzebub are you two TALKING about. NEITHER of you posted anything at all relevant to the question asked by "recOil".

    If you don't stop giving TOTALLY irrelevant answers, I'm going to keep giving you BAD reputation.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  

    Posting Permissions

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