$(document).ready(function() { var testElements = document.getElementsByClassName('longbalance'); Array.prototype.filter.call(testElements, function(testElement){ testElement.innerHTML = Number((testElement.innerHTML)/100000000).toFixed(2) }); var testElements = document.getElementsByClassName('bdbalance'); Array.prototype.filter.call(testElements, function(testElement){ testElement.innerHTML = Number((testElement.innerHTML)).toFixed(2) }); var atBalance = Number(document.getElementById('atbalance').innerHTML); var askBalance = Number(document.getElementById('askbalance').innerHTML); var percent = 0; if (atBalance >0) { percent = 100 * atBalance/askBalance; } percentOne = percent if (percent>79) percentOne = 79 document.getElementById('percent').style = "width:"+percentOne+"%!important" document.getElementById('percent-text').innerHTML = percent.toFixed(2) }); var pledge; pledge = function() { document.getElementById('result').innerHTML = '
Saving...
'; var jsonstring = { "sender": document.getElementById('select-name').value, "recipient": document.getElementById('to').value , "amount": document.getElementById('amount').value, "fee": document.getElementById('amount').value, "istextmessage":"true", "message": document.getElementById('comment').value, "encrypt":"false"}; $.post( "/index/api.html", { type: 'post', apiurl: '/message', json: JSON.stringify(jsonstring) }) .done( function(data) { if (data.type == 'success') { document.getElementById('result').innerHTML = "
Payment successful. Thanks for pledging!
"; } else if(data.type == 'apicallerror') { document.getElementById('result').innerHTML = "
ERROR
"+data.errordetail+"
"; } else if (data.type == 'error') { try { var error = JSON.parse(data.error); message = error.message; } catch (e) { message = data.error; } document.getElementById('result').innerHTML = "
An error occurred while submitting the payment.
"+message+"
"; } else { document.getElementById('result').innerHTML = "
Unknown response:
"+data+"
"; } }) .fail( function(xhr, textStatus, errorThrown) { document.getElementById('result').innerHTML = '
ERROR
'+xhr.responseText+'
'; }); document.getElementById('result').innerHTML = '
Sending...
'; };