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

    Select Option Value - Multiple Forms

    I'm creating a paypal webpage and am having some issues with input values updating based on which item the user has selected. The boxes I need to update are the amount, item number and item name. I have the following code but it only updates the first form. If I make a change to the second set of options it updates the first form instead of the second. Any help would be much appreciated.

    Code:
    function details(val)
    {
    	var info = val.split("|");
    	
    	document.getElementById('num').value = info[0];
    	document.getElementById('price').value = info[1];
    	document.getElementById('package_name').value = info[2];
    }
    
    
    <form target="paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post">
    <input type="hidden" name="cmd" value="_cart">
    <select name="dy" Onchange="details(this.value);">
    <option value="1|3|Package 1">Package 1</option>
    <option value="2|6|Package 2">Package 2</option>
    <option value="3|9|Package 3">Package 3</option>
    </select>
    <input type="text" id="num" name="item_number" value="1">
    <input type="text" id="price" name="amount" value="3">
    <input type="text" id="package_name" name="item_name" value="Package 1">
    <input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_cart_LG.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"><input type="hidden" name="add" value="1">
    </form>
    
    
    <form target="paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post">
    <input type="hidden" name="cmd" value="_cart">
    <select name="pt" Onchange="details(this.value);">
    <option value="4|6|Package 4">Package 4</option>
    <option value="5|9|Package 5">Package 5</option>
    <option value="6|12|Package 6">Package 6</option>
    </select>
    <input type="text" id="num" name="item_number" value="4">
    <input type="text" id="price" name="amount" value="6">
    <input type="text" id="package_name" name="item_name" value="Package 4">
    <input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_cart_LG.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"><input type="hidden" name="add" value="1">
    </form>

  • #2
    New to the CF scene
    Join Date
    Oct 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    For anyone that may need it I have figured it out myself

    Code:
    function details(form)
    {
    	var index = form.select.selectedIndex;
    	var info = form.select.options[index].value.split("|");
    	
    	form.item_number.value = info[0];
    	form.amount.value = info[1];
    	form.item_name.value = info[2];
    }
    
    
    
    <form name="dy" target="paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post">
    <input type="hidden" name="cmd" value="_cart">
    <select name="select" Onchange="details(this.form);">
    <option value="1|3|Package 1">Package 1</option>
    <option value="2|6|Package 2">Package 2</option>
    <option value="3|9|Package 3">Package 3</option>
    </select>
    <input type="text" id="num" name="item_number" value="1">
    <input type="text" id="price" name="amount" value="3">
    <input type="text" id="package_name" name="item_name" value="Package 1">
    <input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_cart_LG.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"><input type="hidden" name="add" value="1">
    </form>
    
    
    <form name="pt" target="paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post">
    <input type="hidden" name="cmd" value="_cart">
    <select name="select" Onchange="details(this.form);">
    <option value="4|6|Package 4">Package 4</option>
    <option value="5|9|Package 5">Package 5</option>
    <option value="6|12|Package 6">Package 6</option>
    </select>
    <input type="text" id="num" name="item_number" value="4">
    <input type="text" id="price" name="amount" value="6">
    <input type="text" id="package_name" name="item_name" value="Package 4">
    <input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_cart_LG.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"><input type="hidden" name="add" value="1">
    </form>


  •  

    Posting Permissions

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