SHARE
TWEET

Untitled

a guest Sep 14th, 2017 99 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. HTML:
  2. <label id="lblParentTeam">Parent Team:</label>
  3. <select id="ddlParentTeam" name="ParentTeam"></select>
  4.  
  5. JavaScript:
  6. var siteurl = "https://dev.test.net/sites/Dev/POC";
  7. var collListItem;
  8. $(document).ready(function () {
  9. SP.SOD.executeFunc('sp.js', 'SP.ClientContext', parentTeamListDrpDownBind);
  10. });
  11.  
  12. function parentTeamListDrpDownBind() {
  13. bindDropDown("Parent Team", "ddlParentTeam", '<View><Query><OrderBy>
  14. <FieldRef Name="Title" /></OrderBy></Query></View>');
  15.  }
  16.  
  17. function bindDropDown(listName, controlID, query) {
  18.  
  19. var clientContext = new SP.ClientContext(siteurl);
  20. var oList = clientContext.get_web().get_lists().getByTitle(listName);
  21.  
  22. var camlQuery = new SP.CamlQuery();
  23. camlQuery.set_viewXml(query);
  24. collListItem = oList.getItems(camlQuery);
  25. clientContext.load(collListItem, 'Include(ID,Title)');
  26. clientContext.executeQueryAsync(
  27.     Function.createDelegate(this, this.onQuerySucceeded),
  28.     Function.createDelegate(this, this.onQueryFailed)
  29.     );
  30. }
  31.  
  32. function onQuerySucceeded(sender, args) {
  33. alert('From Success');
  34. var listItemInfo = '';
  35. var dropdown = $('#ddlParentTeam');
  36. dropdown.empty();
  37. var listItemEnumerator = collListItem.getEnumerator();
  38. while (listItemEnumerator.moveNext()) {
  39.     alert('alert from While');
  40.     var oListItem = listItemEnumerator.get_current();
  41.     var itemText = oListItem.get_item('Title');
  42.     var itemId = oListItem.get_item('ID');
  43.     $("#" + dropdown).append('<option value="' + itemId + '">' + itemText +
  44.   '</option>');
  45.  
  46.    }
  47.  }
  48.  
  49.  function onQueryFailed(sender, args) {
  50.         alert('Request failed in Bind Dropdown ' + args.get_message() + 'n'
  51.    + args.get_stackTrace());
  52. }
RAW Paste Data
Top