title: Uncaught TypeError: Cannot read property 'submit' of null for stripe payment
body: <p>I am integrating stripe payments into my app.  I switched out the Stripe default "Pay with Card" button for one I customized.  After doing this, the test mode successfully pops-up and I can enter the test credentials. However, when I submit the test payment, and it is approved, it just stays on the same pin page rather than going to the charges page that I created for it. </p>
  
  <p>Note: the app would transition just fine from stripe payment to the charges create.html.erb page up until I replaced the default stripe payment button with my new customized button.</p>
  
  <p>Also, looking at developer tools I do note that it reads when I submit test payment: </p>
  
  <pre><code>Uncaught TypeError: Cannot read property 'submit' of null 
  </code></pre>
  
  <p>I think this is referring to my code below where I submit the chargeForm.</p>
  
  <p>Anyone encounter this issue before or know I can fix this?  Many thanks!</p>
  
  <p>app/views/pins/_details.html.erb</p>
  
  <p></p>
  
  <pre><code>        &lt;%= form_tag charges_path, id: 'chargesForm' do %&gt;
            &lt;script src="https://checkout.stripe.com/checkout.js"&gt;&lt;/script&gt;
            &lt;%= hidden_field_tag 'stripeToken' %&gt;
            &lt;%= hidden_field_tag 'stripeEmail' %&gt;  
            &lt;button id="btn-buy" type="button" class="btn btn-success btn-lg btn-block"&gt;&lt;span class="glyphicon glyphicon-heart"&gt;&lt;/span&gt;   I want this!&lt;/button&gt;
  
            &lt;script&gt;
            var handler = StripeCheckout.configure({
              key: '&lt;%= Rails.configuration.stripe[:publishable_key] %&gt;',
              token: function(token, arg) {
                document.getElementById("stripeToken").value = token.id;
                document.getElementById("stripeEmail").value = token.email;
                document.getElementById("chargeForm").submit();
              }
            });
             document.getElementById('btn-buy').addEventListener('click', function(e) {
              handler.open({
                name: 'OMG! &lt;%= @pin.manufacturer %&gt;',
                description: '&lt;%= @pin.description %&gt;',
                amount: 1000
            });
            e.preventDefault();
           })
          &lt;/script&gt;
        &lt;% end %&gt;
  </code></pre>
  
  <p>app/controllers/charges_controller.rb</p>
  
  <pre><code>class ChargesController &lt; ApplicationController
  
  def create
    # Amount in cents
    @amount = 500
  
    customer = Stripe::Customer.create(
      :email =&gt; params[:stripeEmail],
      :card  =&gt; params[:stripeToken]
    )
  
    charge = Stripe::Charge.create(
      :customer    =&gt; customer.id,
      :amount      =&gt; @amount,
      :description =&gt; 'Rails Stripe customer',
      :currency    =&gt; 'usd'
    )
  
      rescue Stripe::CardError =&gt; e
        flash[:error] = e.message
        redirect_to charges_path
     end
  
  end
  </code></pre>
  
  <p>app/views/charges/create.html.erb</p>
  
  <pre><code>You bought some Awesome stuff!
  </code></pre>
  
  <p>app/config/routes.rb</p>
  
  <pre><code>Rails.application.routes.draw do
    resources :pins
    resources :charges
  
    devise_for :users
    root "pins#index"
    get "about" =&gt; "pages#about" #creates about_path
    get "contact" =&gt; "pages#contact" #creates contact_path
    get "auction" =&gt; "pages#auction" #creates auction_path
    get "terms" =&gt; "pages#terms" #creates terms_path
    post 'send_mail', to: 'contact#send_mail'
    get 'contact', to: 'contact#show'
  
   scope 'pins', controller: :pins do
      scope '/:id' do
       post 'bid', to: :bid
      end
   end
  
    scope 'admin', controller: :admin do
      scope 'pins' do
        get '/:pin_id', to: :pin
      end
    end
  end
  </code></pre>