I am a complete JS noob, so bear with me please.
I got a simple JS to query yahoo stock price, which is working great, however for some reason i cannot pass the result variable to another function, where i would like to perform some other calculations with it. I pasted the simplified version here.
If someone could help i would appreciate it, so i couldn't figure this out, all morning. :(
Thanks!
var result = "0";
function onBodyLoad(){
getQuote();
var balance = "100";
var leverage = balance/result;
$("#leverage_result").text(leverage);
}
function getQuote(){
var url = "http://query.yahooapis.com/v1/public/yql";
var symbol = $("#symbol").val();
symbol = "^GSPC";
var data = encodeURIComponent("select * from yahoo.finance.quotes where symbol in ('" + symbol + "')");
$.getJSON(url, 'q=' + data + "&format=json&diagnostics=true&env=http://datatables.org/alltables.env")
.done(function (data) {
result = parseInt(data.query.results.quote.LastTradePriceOnly);
});
}
<body onload="onBodyLoad()">
<div id='leverage_result'>No Price</div>
</body>