Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

239
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda