title: Passing javascript variable to Paypal
body: <p>I am trying to pass a variable amount (this being the total order value) to the 'amount' variable in a paypal form. However, the value is generated from a drop down list. I've scoured the forums and tried a few things, but can't find what I thought would be a simple solution.</p>
  
  <p>Below is the code. </p>
  
  <p>As you can see there are a couple of options I have tried, but neither pass the variable selected from the drop down list.</p>
  
  <p>I appreciate the issues with Paypal security... but that aside, is there anyone with a much larger brain than mine who can spot an obvious solution.</p>
  
  <p>Thanks!!</p>
  
  <p>Andy</p>
  
  <p>PS If I change the var 'andy' to, say, 33, it all works fine.</p>
  
  <p>
  </p>
  
  <pre><code>&lt;label for="CurrentExcess"&gt;Current Excess (£100 - £500 Max.)&lt;/label&gt;
  
  &lt;select id="dropdown"&gt; 
    &lt;option value="invalid entry"&gt;please select&lt;/option&gt;
    &lt;option value="12"&gt;£100&lt;/option&gt;
    &lt;option value="18"&gt;£150&lt;/option&gt;
    &lt;option value="24"&gt;£200&lt;/option&gt;
    &lt;option value="30"&gt;£250&lt;/option&gt;
    &lt;option value="36"&gt;£300&lt;/option&gt;
    &lt;option value="42"&gt;£350&lt;/option&gt;
    &lt;option value="48"&gt;£400&lt;/option&gt;
    &lt;option value="54"&gt;£450&lt;/option&gt;
    &lt;option value="60"&gt;£500&lt;/option&gt;
    &lt;option value="all us to discuss"&gt;more then £500&lt;/option&gt;
  &lt;/select&gt; 
  
  
          &lt;/div&gt;
          &lt;div&gt;
  &lt;label for="price"&gt;Your membership fee will be: £&lt;/label&gt;
  &lt;input type="text" name="price" value="" id="mytext" /&gt;
  
  &lt;script type="text/javascript"&gt;
  var mytextbox = document.getElementById('mytext'); 
  var mydropdown = document.getElementById('dropdown'); 
  mydropdown.onchange = function(){ 
        mytextbox.value = this.value; 
  } 
  document.getElementById("finalpaypal").value = mytext;
  var andy = mytext
  &lt;/script&gt;
  
  
  &lt;form name="_xclick" action="https://www.paypal.com/cgi-bin/webscr" method="post"&gt;
  &lt;input type="hidden" name="cmd" value="_cart"&gt;
  &lt;input type="hidden" name="business" value="me@me.com"&gt;
  &lt;input type="hidden" name="item_name" value="My Title"&gt;
  &lt;input type="hidden" name="quantity" value="1"&gt;
  &lt;input type="hidden" name="item_number" value="11"&gt;
  &lt;!-- &lt;script&gt; 
  document.write('&lt;input type="hidden" name="amount" value='+andy+'&gt;'); 
  &lt;/script&gt; --&gt;
  &lt;input type="hidden" name="amount" id="finalpaypal"&gt;
  &lt;input type="hidden" name="no_note" value="1"&gt;
  &lt;input type="hidden" name="currency_code" value="GBP"&gt;
  &lt;input type="hidden" name="add" value="1"&gt;
  
  &lt;/form&gt;
  
  
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>UPDATE: Thanks for the input from sdleihssirhc. That does help, but as I am a bit of a duffer with javascript am still struggling.</p>
  
  <p>The bit I didn't emphasise is that I am trying to get the value from 'mytext' into 'amount' which is passed to paypal. And I dont care how, but it seems that as the value is calculated with an 'OnChange'....it all goes a bit bonkers.</p>
  
  <p>The main bits of code now read as below on last bit of post.</p>
  
  <p><strong>ANY BRIGHT IDEAS ANYONE. MANY THANKS!!!!</strong></p>
  
  <p>
  </p>
  
  <pre><code>&lt;label for="CurrentExcess"&gt;Current Excess (£100 - £500 Max.)&lt;/label&gt;
  
  &lt;select id="dropdown"&gt; 
    &lt;option value="invalid entry"&gt;please select&lt;/option&gt;
    &lt;option value="12"&gt;£100&lt;/option&gt;
    &lt;option value="18"&gt;£150&lt;/option&gt;
    &lt;option value="24"&gt;£200&lt;/option&gt;
    &lt;option value="30"&gt;£250&lt;/option&gt;
    &lt;option value="36"&gt;£300&lt;/option&gt;
    &lt;option value="42"&gt;£350&lt;/option&gt;
    &lt;option value="48"&gt;£400&lt;/option&gt;
    &lt;option value="54"&gt;£450&lt;/option&gt;
    &lt;option value="60"&gt;£500&lt;/option&gt;
    &lt;option value="all us to discuss"&gt;more then £500&lt;/option&gt;
  &lt;/select&gt; 
  
  
          &lt;/div&gt;
          &lt;div&gt;
  &lt;label for="price"&gt;Your membership fee will be: £&lt;/label&gt;
  &lt;input type="text" name="price" value="" id="mytext" /&gt;
  &lt;form name="_xclick" action="https://www.paypal.com/cgi-bin/webscr" method="post"&gt;
  &lt;input type="hidden" name="cmd" value="_cart"&gt;
  &lt;input type="hidden" name="business" value="me@me.com"&gt;
  &lt;input type="hidden" name="item_name" value="My Title"&gt;
  &lt;input type="hidden" name="quantity" value="1"&gt;
  &lt;input type="hidden" name="item_number" value="11"&gt;
  &lt;input type="hidden" name="amount" id="finalpaypal"&gt;
  &lt;input type="hidden" name="no_note" value="1"&gt;
  &lt;input type="hidden" name="currency_code" value="GBP"&gt;
  &lt;input type="hidden" name="add" value="1"&gt;
  
  &lt;/form&gt;
  
  &lt;script&gt; 
  var mytextbox = document.getElementById('mytext');  
  var mydropdown = document.getElementById('dropdown');  
  var finalpaypal = document.getElementById('finalpaypal'); 
  mydropdown.onchange = function(){  
  mytextbox.value = this.value; 
  finalpaypal.value = this.value; 
  }  
  document.getElementById("finalpaypal").value = mytext; 
  &lt;/script&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>