title: How can I use JS to assign a value on an input based on a key?
body: <p>Okay, take two.
  Before you continue reading please note that I know basically ZERO JS so if I display some extreme stupidity, I'm trying my best.</p>
  <p>I am attempting to implement PayPal into a website I'm creating and I found a <a href="https://developer.paypal.com/api/nvp-soap/paypal-payments-standard/integration-guide/html-example-buy-now/#a-basic-buy-now-button" rel="nofollow noreferrer">button</a> on the PayPal website that was basically exactly what I'm looking for.</p>
  <p>I already have a working cart price calculation system that I've had in place for a while now and calculates Sales Tax/Shipping/The total price of the items in the cart <code>TotalPrice</code> and puts it into one h1 tag using <code>document.getElementByID('ID').innerHTML = `$${localStorage.getItem('TotalPrice')}` </code> This works perfectly well, and has for a few months.</p>
  <p>The button code exactly from the PayPal website is as follows:</p>
  <pre><code>&lt;form action=&quot;https://www.paypal.com/cgi-bin/webscr&quot; method=&quot;post&quot;&gt; 
  &lt;!-- Identify your business so that you can collect the payments. --&gt; &lt;input type=&quot;hidden&quot; name=&quot;business&quot; value=&quot;herschelgomez@xyzzyu.com&quot;&gt;
   &lt;!-- Specify a Buy Now button. --&gt; 
  &lt;input type=&quot;hidden&quot; name=&quot;cmd&quot; value=&quot;_xclick&quot;&gt; 
  &lt;!-- Specify details about the item that buyers will purchase. --&gt; 
  &lt;input type=&quot;hidden&quot; name=&quot;item_name&quot; value=&quot;Hot Sauce-12oz. Bottle&quot;&gt; 
  &lt;input type=&quot;hidden&quot; name=&quot;amount&quot; value=&quot;5.95&quot;&gt; 
  &lt;input type=&quot;hidden&quot; name=&quot;currency_code&quot; value=&quot;USD&quot;&gt; 
  &lt;!-- Display the payment button. --&gt; 
  &lt;input type=&quot;image&quot; name=&quot;submit&quot; border=&quot;0&quot; src=&quot;https://www.paypalobjects.com/en_US/i/btn/btn_buynow_LG.gif&quot; alt=&quot;Buy Now&quot;&gt; 
  &lt;img alt=&quot;&quot; border=&quot;0&quot; width=&quot;1&quot; height=&quot;1&quot; src=&quot;https://www.paypalobjects.com/en_US/i/scr/pixel.gif&quot; &gt; &lt;/form&gt;
  </code></pre>
  <p>and the value that actually sets the price PayPal charges once the form is submitted is in the hidden input with the name &quot;amount&quot;. I figured that it would be relatively easy to set the value of that input by adding an ID and using similar logic to the working cart system. Here is what I have now:</p>
  <pre><code>&lt;form action=&quot;https://www.paypal.com/cgi-bin/webscr&quot; method=&quot;post&quot;&gt; 
                  &lt;!-- Identify your business so that you can collect the payments. --&gt; 
                  &lt;input type=&quot;hidden&quot; name=&quot;business&quot; value=&quot;website@gmail.com&quot;&gt; 
                  &lt;!-- Specify a Buy Now button. --&gt; 
                  &lt;input type=&quot;hidden&quot; name=&quot;cmd&quot; value=&quot;_xclick&quot;&gt; 
                  &lt;!-- Specify details about the item that buyers will purchase. --&gt; 
                  &lt;input type=&quot;hidden&quot; name=&quot;item_name&quot; value=&quot;Checkout&quot;&gt; 
                  &lt;input type=&quot;hidden&quot; name=&quot;amount&quot; id=&quot;pricebutton&quot; &gt; 
                  &lt;input type=&quot;hidden&quot; name=&quot;currency_code&quot; value=&quot;USD&quot;&gt; 
                  &lt;!-- Display the payment button. --&gt; 
                  &lt;input type=&quot;submit&quot; name=&quot;submit&quot; border=&quot;0&quot; id=&quot;checkoutbtn&quot; alt=&quot;Buy Now&quot; value=&quot;Checkout Using Paypal&quot; onclick=&quot;payPal()&quot;&gt;
              &lt;/form&gt;
  </code></pre>
  <p>I also added some JS</p>
  <pre><code>&lt;script&gt;
  function payPal() {
      document.getElementById('pricebutton').value = localStorage.getItem('TotalPrice');
  }
  &lt;/script&gt; 
  </code></pre>
  <p>What I tried to do was, when the button is clicked and the form is submitted, change the value of the form so that it matches the total value of the items in the cart, <code>TotalPrice</code>. What have I done wrong?</p>
  <p>If you need more information, I will do my best to provide it through edits &amp; comments.
  Thanks.</p>