populate select Options - Download Dynamically Populate Select Options - jQuery popSelectOptions

Download Dynamically Populate Select Options – jQuery popSelectOptions

Posted on

This time I will share jQuery Plugin and tutorial about Dynamically Populate Select Options – jQuery popSelectOptions, hope it will help you in programming stack.

populate select Options - Download Dynamically Populate Select Options - jQuery popSelectOptions
File Size: 4.82 KB
Views Total: 2540
Last Update:
Publish Date:
Official Website: Go to website
License: MIT
   

popSelectOptions is a really small (~1kb) jQuery plugin for dynamic dropdown list that dynamically loads and populates a select element with options defined in a JS array.

How to use it:

1. Include the jQuery popSelectOptions plugin on the page where needed. Be sure to include it after the latest jQuery.

2         integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8="
3         crossorigin="anonymous">
4 </script>
5 <script src="jquery.popSelectOptions.min.js"></script>

2. Define an array of objects containing labels and values for select options.

1 const myData = [
2       {'value': '1', 'label': 'jQueryScript'},
3       {'value': '2', 'label': 'CSSSCRIPT'},
4       {'value': '3', 'label': 'AngularJS'},
5       {'value': '4', 'label': 'React Native'},
6       {'value': '5', 'label': 'Vue.js'}
7 ];

3. Attach the function popSelectOptions to an empty select element and specify the data source as follows:

1 <select id="example"></select>
1 $(function() {
2   $('#example').popSelectOptions({
3     'options': distances
4   });
5 })

4. Set the initial option on page load. Default: 0.

1 $(function() {
2   $('#example').popSelectOptions({
3     'options': 2 // option 3
4   });
5 })

This awesome jQuery plugin is developed by gar-cad. For more Advanced Usages, please check the demo page or visit the official website.

source : jquery.net