Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

javascript make function parameters dynamic

so I am trying to include payment API checkout on my order.html page, however, you must add a script in the head of HTML document. in the script, you must specify the subtotal amount as a number, but I need this value to be dynamic. the "stotal" is the subtotal amount. I need to set subtotal to whatever the "stotal" is. How I do this?

<head>
  <script type="text/javascript">
    function paymentApi() {
      V.init({
        apikey: "",
        encryptionKey: "",
        paymentRequest: {
          currencyCode: "USD",
          subtotal: "11.00"
        }
      });
  </script>
</head>

<body>
  <p id="sub-total">
    <strong>Total</strong>: <span id="stotal"></span>
  </p>
like image 526
dilbert Avatar asked Nov 26 '22 17:11

dilbert


1 Answers

Just change subtotal to get the value from the html as follows

<script type="text/javascript">
function paymentApi(){
    V.init( {
    apikey: "",
    encryptionKey: "",
    paymentRequest:{
        currencyCode: "USD",
        subtotal: document.getElementById('stotal').innerText //Here
    }
    });
</script>
like image 74
SoWhat Avatar answered Dec 18 '22 18:12

SoWhat