Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

235
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!