Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

Populate a Select Dropdown List using JSON

let dropdown = $('#locality-dropdown');

dropdown.empty();

dropdown.append('<option selected="true" disabled>Choose State/Province</option>');
dropdown.prop('selectedIndex', 0);

const url = 'https://api.myjson.com/bins/7xq2x';

// Populate dropdown with list of provinces
$.getJSON(url, function (data) {
  $.each(data, function (key, entry) {
    dropdown.append($('<option></option>').attr('value', entry.abbreviation).text(entry.name));
  })
});
Comment

PREVIOUS NEXT
Code Example
Javascript :: How do I target and change the style of a different element when I click a button in react 
Javascript :: shrinkStringByRepeatFactor 
Javascript :: react private routes 
Javascript :: Backbone View Notes 
Javascript :: for-loop-how-to-loop-through-an-array-in-js 
Javascript :: create number format excel react native 
Javascript :: js check that interactive element is not focused 
Javascript :: nested object in javascript 
Javascript :: convert text to number 
Javascript :: insert element in array javascript 
Javascript :: axios response error interceptor 
Javascript :: use of prototype in javascript 
Javascript :: table to excel javascript 
Javascript :: moment duration 
Javascript :: regex in javascript 
Javascript :: angular cli command to create component without spec 
Javascript :: javascript json to excel 
Javascript :: noise expression after effects 
Javascript :: js pick last element of array 
Javascript :: How to print even and odd position characters of an array of strings in JavaScript 
Javascript :: JavaScript for loop Display Numbers from 1 to 5 
Javascript :: javascript Display Undeclared Variable 
Javascript :: JavaScript pauses the async function until the promise 
Javascript :: socket io join multiple rooms 
Javascript :: suitescript get lineitemcount 
Javascript :: nodejs: express, morgan, mongoose package 
Javascript :: Json to npy file 
Javascript :: phaser multi atlas animation 
Javascript :: Pretty-Print JSON within Neovim 
Javascript :: reactjs moment to string 
ADD CONTENT
Topic
Content
Source link
Name
5+1 =