populate options from json - Free Download Dynamically Populate Options Of A Select Element From JSON

Free Download Dynamically Populate Options Of A Select Element From JSON

Posted on

This time I will share jQuery Plugin and tutorial about Dynamically Populate Options Of A Select Element From JSON, hope it will help you in programming stack.

populate options from json - Free Download Dynamically Populate Options Of A Select Element From JSON
File Size: 4.16 KB
Views Total: 388
Last Update:
Publish Date:
Official Website: Go to website
License: MIT
   

Have you ever wanted to bind JSON data to a dropdown list?

Here is a jQuery plugin that makes it possible to dynamically populate options of a native select element from a JSON file (or JSON API) you provide.

Ultra lightweight and easy to implement. You can easily modify the JS code to match your data set.

How to use it:

1. To get started, insert the JavaScript index.js after loading the latest jQuery JavaScript library.

1 <script src="/path/to/cdn/jquery.min.js"></script>
2 <script src="index.js"></script>

2. Initialize the plugin on your select element and specify the path to the JSON data.

1 <select id="myDropdown"></select>
1 $('#myDropdown').dynamicDropdown({
2   url: 'json.json'
3 });
01 // data.json
02 [
03   {"name":"jQuery", "url":"jQueryScript.net"},
04   {"name":"JS & CSS", "url":"CSSScript.com"},
05   {"name":"Google", "url":"Google.com"},
06   {"name":"Youtube", "url":"Youtube.com"},
07   {"name":"<a href="https://www.jqueryscript.net/tags.php?/Facebook/">Facebook</a>", "url":"Facebook.com"},
08   {"name":"Instagram", "url":"Instagram.com"},
09   // more data here
10 ]

3. Determine the key & value names if necessary.

1 $('#myDropdown').dynamicDropdown({
2   url: 'json.json',
3   key: '',
4   value: 'url'
5 });