Im having a hard time understanding how to get a search from an html search box and input it into a api link on the JS side. i want something like this to work
$.getJSON(`https://www.alphavantage.co/query?function=TIME_SERIES_DAILY&symbol=$(".stock-name")&apikey=APIKEY`,
function(data){
console.log(data);
var date = data["Meta Data"]["3. Last Refreshed"];
var stock = data["Meta Data"]["2. Symbol"];
var info = data["Meta Data"]["1. Information"];
var open = data["Time Series (Daily)"][date]["1. open"];
var close = data["Time Series (Daily)"][date]["4. close"];
var high = data["Time Series (Daily)"][date]["2. high"];
var low = data["Time Series (Daily)"][date]["3. low"];
var vol = data["Time Series (Daily)"][date]["5. volume"];
var difference = close-open;
$(".Stock-Name").append(stock);
$(".info").append(info);
$(".stock-open").append(open);
$(".stock-close").append(close);
$(".difference").append(difference);
$(".date").append(date);
$(".high").append(high);
$(".low").append(low);
$(".vol").append(vol);
if(difference < 0){
$(".stock").css("background-color", "red");
}
else{
$(".stock").css("background-color", "green");
}
}
);
where in the url symbol=$(".stock-name") would be the name of the stock the user inputs on my front end and it would show the info from the array in the api.