我正在尝试使用函数的值/结果作为我的单选按钮值,但我似乎无法正确使用。
在下面的表格中,我想使用'calcDogecoins()'的结果成为单选按钮的值。然后我继续用PHP将这个值发送给自己。
<form name="buynow" method="post" action="send_form_email.php">
<input type="radio" name="cardamount" value="" onclick="calcDogecoins()">Choose Gift Card Value<br>
</form>
这是我想要成为按钮值的相关功能。此函数接受用户输入,将其乘以从API中提取的值并返回计算的Dogecoin实时价格。
<script>
function calcDogecoins() {
var resultedDogecoins;
var giftValue = prompt("What Value Gift Card Would You Like To Purchase?", "");
if (giftValue != null) {
// constants
var valueEntered = 1;
var ONE_DOGE = '1 DOGE = ';
var ONE_USD = '$' + valueEntered + ' gift card costs: ';
// cryptsy's public API for DOGE, mtgox's for BTC
var dogeApiUrl = 'http%3A%2F%2Fpubapi.cryptsy.com%2Fapi.php%3Fmethod%3Dsinglemarketdata%26marketid%3D132';
var btcApiUrl = 'http://data.mtgox.com/api/1/BTCUSD/ticker_fast';
// node cross domain proxy server
var jsonPWrapper = 'https://jsonp.nodejitsu.com/?callback=?&url=';
$.getJSON(jsonPWrapper + dogeApiUrl, function(data) {
var dogePrice = data.
return .markets.DOGE.lasttradeprice;
$("div.btc").html(ONE_DOGE + 'B' + dogePrice);
$.getJSON(jsonPWrapper + btcApiUrl, function(data) {
var btcPrice = data.
return .buy.value;
$("div.usd").html(ONE_DOGE + '$' + btcPrice * dogePrice);
var dogecost = (Math.floor(((((1 / (btcPrice * dogePrice))*1.05) * valueEntered) * 100) / 100));
//var finalAmount = (dogecost * enteredAmount);
//alert(finalAmount);
resultedDogecoins = "The cost of a $" + giftValue + " gift card is " + giftValue * dogecost + " Dogecoins.";
document.getElementById("doges").innerHTML = resultedDogecoins;
});
});
}
}
</script>