Updating a <script> element on form submission

I'm using Stripe for payment processing, which uses an inline <script></script> within a <form> element, like so:

<form action="" method="POST" id="payButton" style="display:none;">
  <script
    src="https://checkout.stripe.com/checkout.js" class="stripe-button"
    data-key="myprivatekeygoeshere"
    data-amount="4900"
    data-name="Sample Name"
    data-description="We use Stripe for 100% secure payment processing."
    data-image="/agm-128-128.png"
    data-email="THIS IS WHAT I'D LIKE TO CHANGE"
  </script>
</form>

This form is step 2 of a two-part validation. The first gets a user's info, like name, email address, location and saves it to my server. Once this happens, this Stripe form is opened.

Inside the script, there's an option for data-email. This auto-fills a user's email address and I'd like to update this based on a user's input in step 1 of the form.

Using Javascript or jQuery, is it possible to achieve this?

Something along the lines of:

$('#form1').submit(function(){
  var email = $('#form1 #email').val();
  $('#payButton script').attr('data-email', email);
});

Possible duplicate of this question which didn't have a proper resolution and is 3 yeas old: jQuery > Update inline script on form submission

Answers


The answer was, hilariously/stupidly, in the question - thanks to @probackpacker, who got me to test the dummy code that I posted as an example of what wouldn't work. It actually did work:

$('#form1').submit(function(){
  var email = $('#form1 #email').val();
  $('#payButton script').attr('data-email', email);
});

This correctly targets the <script> tag and lets you change the attributes.


Need Your Help

"error: conflicting types for ‘sem_t’" when compiling eglibc-2.19 on Ubuntu

c ubuntu compiler-errors building eglibc

I was trying to build eglibc-2.19 on Ubuntu 14.04 LTS which I downloaded through

Windows Phone - Using ContextMenu for Images in a WrapPanel

wpf silverlight windows-phone-8

I have a wrap panel that is populated with Image controls at run time. I want to use a context menu to remove images I want to delete.