šŸ”” Alert..!! Get 2 Month Free Cloud Hosting With $200 Bonus From Digital Ocean ACTIVATE DEAL

selectAjax is a very small jQuery plugin that automatically populates select options with JSON-encoded data via AJAX requests.

ajax Select

Documentation

selectajax

A jQuery plugin to populate <option> element of html <select> input from ajax datasource.

Usage

<select id="selectCountry"></select>
<script src="jquery.js"></script> <script src="selectajax.js"></script>  $('#selectCountry').getOptions({     url: "/api/country",     key: "countryName",     val: "alpha2Code",     firstOption: {         key: "Select Country",         val: ""     } });

url returns -

[     {         countryName: "Bangladesh",         alpha2Code:"BD"     },     {         countryName: "Bhutan",         alpha2Code:"BT"     },     {         countryName: "Malaysia",         alpha2Code:"MY"     }     ...         ]

Result:

<select id="selectCountry">     <option value="">Select Country</option>     <option value="BD">Bangladesh</option>     <option value="BT">Bhutan</option>     <option value="MY">Malaysia</option>     ... </select>

DEMO (by Anowar)


You May Also Like