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

69
Views
Populate drop-down from database in Javascript

(In Javascript) I am doing a GET request inside typefunc() and getting result (variable res) in this format:-

[{"Name":"Button1","ID":"A1"}, {"Name":"Button2","ID":"A2"}, {"Name":"Button3","ID":"A3"}]

How do I populate the below mentioned drop-down using this data?

<select id="type" class="form-control" onchange="typefunc();" required>
    <option selected>Choose...</option>
</select>
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

This is a demo showing how to create option elements to append to the target dropdown based on the options object:

const options = [
  {"Name":"Button1","ID":"A1"},
  {"Name":"Button2","ID":"A2"},
  {"Name":"Button3","ID":"A3"}
];

populateDropdown();

function populateDropdown(){
  const dd = document.getElementById('type');
  for(let option of options){  
    const newOption = document.createElement('option');
    const optionText = document.createTextNode(option.Name);
    newOption.appendChild(optionText);
    newOption.setAttribute('value',option.ID);  
    dd.appendChild(newOption);
  }
}
<select id="type" class="form-control" onchange="typefunc();" required>
    <option selected>Choose...</option>
</select>

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!