Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

106
Visualizações
How can i pass data forward base upon what the user clicks on?

I've been testing out fetching data from a stock API and I'm displaying the ticker symbol and name on my page, However, I want to expand a bit and when I click on each stock I would like for a page to open and display more data on that stock. So my approach to the problem is to have a function perform a request using the ticker symbol as the argument when the detail page opens. But my question is how do I pass the ticker forward to my function. Can someone help?

// Fetch stock- this function runs on page load
async function fetchTrendingStock() {
    fetch(trendUrl)
     .then(response => {
         if(!response.ok) {
             throw new Error(`HTTP error! Status: ${response.status}`);
         }
         return response.json();
     })
     .then(data => {
         console.log(data)
         let trend = "";
         let payload = data.data.all;
         for(let i = 0, len = payload.length; i < len; i++) {
            trend += 
            `   
                <div class="col-lg-6">


                <a class="cardLink"  href="details.html">


                        <div class="newsCard">
                            <div class="text-container">
                                <h4 class="cardText">${payload[i].name}</h4>
                                <h5 class="cardText">${payload[i].ticker}</h5>
                            </div>

                            <div class="imgContainer">
                                <p class="">${payload[i].sentiment_score}</p>
                            </div>
                        </div>

                </a>

                </div>

            `
         }
         document.getElementById("trend-stocks-container").innerHTML = trend;

     })
}
fetchTrendingStock()


// fetch stock details- this function will run when the link to the stock is clicked to open the detail page.
 async function fetchProfileData(ticker) {
        let url = `https://financialmodelingprep.com/api/v3/profile/${ticker}?apikey=0000`;

        fetch(url)
         .then(response => {
            if(!response.ok) {
             throw new Error(`HTTP error! Status: ${response.status}`);
            }
            return response.json();
         })
         .then(data => {
             console.log(data)
             data.forEach(payload => {
                 console.log(payload.companyName)
                 console.log(payload.description)
             })
         })
    }
    fetchProfileData("eman")
about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda