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?
<input type="submit" name="oplata" class="oplata" value="PAY"> 

<script id="paymaster" type="text/javascript" src="<?php echo $a; ?>"></script>
June 3rd 19 at 19:21
2 answers
June 3rd 19 at 19:23
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
addScript("<?php echo $a; ?>");

function addScript( src,callback) {
 var s = document.createElement( 'script' );
 s.setAttribute( 'src', src );
 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