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

231
Views
How to bind data to bootstrap select

json data:

["string 1","string 2","test 07 ","here is test"]

and this is html

  <select class="selectpicker" id="ddl_location">
    <option select="selected">Select Location </option>
  </select>

and here is JQuery code

 for (var i = 0; i < jsonData.length; i++) {
     $("#ddl_location").append('<option value="' + jsonData[i] + '">' + jsonData[i] + '</option>');
      }

the issue is that

data is not populated in drop-down list

about 4 years ago · Santiago Trujillo
3 answers
Answer question

0

after working around the issue, the solution was :

 var jsonData = JSON.stringify(data);
     $.each(JSON.parse(jsonData), function (idx, obj) {
        $("#ddl_location").append('<option value="' + obj.id + '">' + obj.location + '</option>').selectpicker('refresh');
     });

step 1: stringify received object
step 2: use each function instead of for loop
step 3: parse the data using JSON.parse(jsonData )
step 4: refresh drop-down list every time you append data to drop-down list using .selectpicker('refresh')

about 4 years ago · Santiago Trujillo Report

0

remember to append $select.append(data).selectpicker('refresh'); when you don't get data populate in drop down

about 4 years ago · Santiago Trujillo Report

0

The code seems to work properly.

var jsonData = ["string 1", "string 2", "test 07 ", "here is test"];

for (var i = 0; i < jsonData.length; i++) {
  $("#ddl_location").append('<option value="' + jsonData[i] + '">' + jsonData[i] + '</option>');
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<select class="selectpicker" id="ddl_location">
  <option select="selected">Select Location </option>
</select>

about 4 years ago · Santiago Trujillo 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!