Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function selectBoxCreator(div,label, jsonData, externalClass ){
- //Create the Parent select//
- $(div).append('<label>'+ label +'</label><select class="form-control ' + externalClass + '"><option value=""> Pick Your ' + label + '</options></select>');
- //request the JSON data and parse into the select element
- var select = (div + ' select.' + externalClass)
- $.getJSON(jsonData, function(data){
- //iterate over the data and append a select option
- $.each(data.data, function(key, val){
- if (val.selected === true){
- $(select).append('<option id="' + val.id + '" class="' + val.class + '" selected>' + val.name + '</option>');
- }
- else{
- $(select).append('<option id="' + val.id + '" class="' + val.class + '">' + val.name + '</option>');
- }
- })
- });
- }
Add Comment
Please, Sign In to add comment