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

238
Visualizações
Display in dropdown elements from SQL

I want to display the strings from my variable allCompanies in a dropdown. I tried to list it with javascript like this, but it doesn't work:

function Requests(){
        var companiesList = @Html.Raw(Json.Serialize(allCompanies));
        for (var i = 0; i <= companiesList.length - 1; i++) {
            $('#Company').append('<option value="' + companiesList[i] + '">' + companiesList[i] + '</option>');
        }
    }

My html code:

<div class="row">
  <div class="col-md-6">
        <p>Select company to see requests: </p>
     <select id="Company" name="Company" class="form-control custom-select">
            <option value="">Select company.</option>
     </select>
   </div>
</div>
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

As far as I can see in your HTML code, you are not actually calling the function you created at all under specific call onKeyUp, onChange etc.

Since you only want to fill the select options in order to initialize them (if I am getting this right), you could just initialize them after the HTML page has loaded.

So I would suggest you to simply use your code in the $(document).ready(function()){} as shown below :

$( document ).ready(function() {

    var companiesList = @Html.Raw(Json.Serialize(allCompanies));
    for (var i = 0; i <= companiesList.length - 1; i++) {
        $('#Company').append('<option value="' + companiesList[i] + '">' + companiesList[i] + '</option>');
    }

});
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