How to make download script by pressing a submit?

Hello! There is a script from a third-party service (which loads part of the code) and a submit button.

I need to make the script load only when submit is pressed (since it is in the script a variable that depends on the issue of the script). How to implement it?
Example:
<form>
<input type="submit" name="oplata" class="oplata" value="PAY"> 
</form>

<script id="paymaster" type="text/javascript" src="https://paymaster.ru/ru-RU/widget/Basic/1?LMI_MERCHANT_ID=111&LMI_PAYMENT_AMOUNT=<?php echo $a; ?>"></script>
June 3rd 19 at 19:21
2 answers
June 3rd 19 at 19:23
Here
About action read.
A file-handler(action.php , for example) , send him a request all that is needed. Get it array with what you need and after doing what you want
No, not suitable. Everything works on one page. Should be without reloading the page, the more submit already responsible for sending the forms to the database - brenna53 commented on June 3rd 19 at 19:26
June 3rd 19 at 19:25
Catch event sabmita of the form like this
$("#form-id").on('submit',function(e){
e.preventDefault();
addScript("https://paymaster.ru/ru-RU/widget/Basic/1?LMI_MERCHANT_ID=111&LMI_PAYMENT_AMOUNT=<?php echo $a; ?>");
});

function addScript( src,callback) {
 var s = document.createElement( 'script' );
 s.setAttribute( 'src', src );
s.onload=callback;
 document.body.appendChild( s );
}

if necessary - add callback to download the script.
Code does not run - just show the idea.

Find more questions by tags JavaScriptHTMLjQuery