I'm very new to jquery and js, so forgive me if it's very easy.
I'm trying to make a ticker for cryptocurrency couples for the exchange liqui.
The API and everything works great, but I can't seem to put a variable inside a JSON request function: "dataResults.eth_btc.last" - I want the "eth_btc" part to be the variable "couple" so I can use any couples.
Here's the full code:
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
<link rel="stylesheet" href="main.css">
<meta charset="utf-8">
</head>
<body>
<script src="jquery.js"></script>
<script>
var value = 0;
var color;
$(document).ready(function() {
$("button").click(function(){
var couple = $("#couple").val();
window.setInterval(function(){
var url = 'https://api.liqui.io/api/3/ticker/' + couple;
$.getJSON(url, function(dataResults) {
var newvalue = dataResults.eth_btc.last; //<<<This right here
if (!color) {
color = "blue";
value = newvalue;
document.body.appendChild(document.createElement('p'));
document.querySelector("body p:last-child").id = color;
document.querySelector("#" + color).innerHTML = value;
} else if (value != newvalue) {
var colorid = $('#' + color);
colorid.empty().remove();
if (value > newvalue) {
color = "green";
} else if (value < newvalue) {
color = "red";
}
value = newvalue;
document.body.appendChild(document.createElement('p'));
document.querySelector("body p:last-child").id = color;
document.querySelector("#" + color).innerHTML = value;
}
});
}, 100);
});
});
</script>
<p>Koppel (eth_btc): <input type="text" id="couple" value=""></p>
<button>Laatste prijzen</button>
</body>
</html>