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

201
Visualizações
Javascript function does not execute on page load but executes when called from Console Window

I have a javascript function to append options on a select input field. Below is code snippet:

function loadZoneDropDown(){
    var datas = placesZoneData.zones, a = document.getElementById("route_start_point");
    for(let t in datas){
        var value_data = datas[t];
            $('#route_start_point').append('<option value="'+t+'">'+value_data.data["name"]+'</option>');
        
    }
    sortSelectList(a);
}

This function is called inside a load() function on the <body> tag as below:

function load(){
   //otherFunctions();
    loadZoneDropDown();
}

HTML code:

<html>
  <head></head>
  <body onload="load()">
  </body>
</html>

The page loads and No new option is appended to the #route_start_point select field. When I run the same function directly on console, the script executes and the options are populated. Can you help me figure the problem out. Note that otherFunctions() are running very OK and fine on the webpage. Screenshot of code before console run

Screenshot after console execution of loadZoneDropDown() below: After function execution on console

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