Guest User

Untitled

a guest
Feb 25th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. function selectBoxCreator(div,label, jsonData, externalClass ){
  2. //Create the Parent select//
  3. $(div).append('<label>'+ label +'</label><select class="form-control ' + externalClass + '"><option value=""> Pick Your ' + label + '</options></select>');
  4. //request the JSON data and parse into the select element
  5. var select = (div + ' select.' + externalClass)
  6. $.getJSON(jsonData, function(data){
  7. //iterate over the data and append a select option
  8. $.each(data.data, function(key, val){
  9. if (val.selected === true){
  10. $(select).append('<option id="' + val.id + '" class="' + val.class + '" selected>' + val.name + '</option>');
  11. }
  12. else{
  13. $(select).append('<option id="' + val.id + '" class="' + val.class + '">' + val.name + '</option>');
  14. }
  15. })
  16. });
  17. }
Add Comment
Please, Sign In to add comment