function send_payment_request(e) { let req_button_id = this.id; req_button_id = req_button_id.split("-")[1]; var amount = document.getElementById('amount-' + req_button_id).innerText; amount = amount.replace('$', ''); amount = parseFloat(amount); console.log(amount); var modal = document.getElementById("myModal"); modal.style.display = "block"; fetch('https://34.125.159.121:8081/buyxgold?amount=' + amount) .then(response => { return response.json(); }) .then(data => { console.log("DATA: ", data) modal.style.display = "none"; window.location = data.sign_contract; }); } window.onload = function(e) { var buttons = document.getElementsByTagName('button'); for (let i = 0; i < buttons.length; i++) { buttons[i].addEventListener('click', send_payment_request); } var modal = document.getElementById("myModal"); // var span = document.getElementsByClassName("close")[0]; // span.onclick = function() { // modal.style.display = "none"; // } // window.onclick = function(event) { // if (event.target == modal) { // modal.style.display = "none"; // } // } }