title: use javascript to set value of paypal hidden field to value of asp control
body: <p>I have an aspx order confirmation form.  In the code behind, content is taken from a database and assigned to the Text attribute of a series of asp:Label controls.  On the same page is the "Buy now" form for paypal.  What I would like to do is take the order cost from the database and assign it to the value attribute of the paypal form's "amount" input.  When I try to do it, the value keeps coming back as "undefined."</p>
  
  <p>I have tried several solutions but none seem to be working.  Currently, the code behind assigns the cost to the Value of an asp:hiddenfield control, and the javascript attempts to grab the cost from that control and then assign it to the amount input.</p>
  
  <p>Relevant code:</p>
  
  <p>in code behind 
  ...</p>
  
  <pre><code>costContent2.Value = confirmOrderDataset.Tables[0].Rows[0]["orderCost"].ToString();
  </code></pre>
  
  <p>...</p>
  
  <p>in page: 
  ...</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
  function setAmount() {
  cost = document.getElementById("costContent2").Value;
  document.forms["paypalForm"].amount.Value = cost;
  }
  &lt;/script&gt;
  &lt;/head&gt;
  &lt;body onload="setAmount()"&gt;
  &lt;form runat="server" name="paypalForm" id="paypalForm" action="https://www.paypal.com/cgi-bin/webscr" method="post"&gt;
  &lt;asp:HiddenField runat="server" ID="costContent2" Value="" /&gt;
  &lt;input type="hidden" name="cmd" value="_s-xclick" /&gt;
  &lt;input type="hidden" name="hosted_button_id" value="X5RRRCPCDL7D8" /&gt;
  &lt;input type="hidden" name="amount" value="" /&gt;
  &lt;input type="image" src="https://www.paypalobjects.com/WEBSCR-640-20110429-1/en_US/i/btn/btn_buynowCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!" /&gt;
  &lt;img alt="" border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1" /&gt;
  </code></pre>
  
  <p>...</p>
  
  <p>I have tried changing the amount input to an asp control but I still get "undefined" as the value.  </p>
  
  <p>Thanks for your help!</p>