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

116
Visualizações
Cant get value of the search bar and assign it into API

I cant assign the value to API, I tried giving it a default value then change it but it still not working (I'm new with API's), the variable is city.

searchBtn.addEventListener("click", function(){
        let searchValue = document.getElementById("searchbar").value;
          let city = searchValue;
    })
    
     fetch(`http://api.weatherapi.com/v1/forecast.json?key=${apik}&q=${city}&days=7`)

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

JavaScript has scopes, and the city variable you made is declared inside of a function, while the API call is outside of the function.

You could move the API call into the function, and then it should work.

searchBtn.addEventListener("click", function(){
    let searchValue = document.getElementById("searchbar").value;
    let city = searchValue;
    
    fetch(`http://api.weatherapi.com/v1/forecast.json?key=${apik}&q=${city}&days=7`)
});

about 4 years ago · Juan Pablo Isaza Relatório
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