Skip to content

Instantly share code, notes, and snippets.

@nilayparikh
Created March 4, 2015 15:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nilayparikh/3ea7f9529bf0958c57fd to your computer and use it in GitHub Desktop.
Save nilayparikh/3ea7f9529bf0958c57fd to your computer and use it in GitHub Desktop.
Populate dropdown from SharePoint Site (JSOM)
<select name="departmentDD" title="department" id="departmentDD" onchange="populateDeapartment(this.value)">
function populateDeapartment(selectedValue) {
$('#DeapartmentDD option').each(function () {
if ($(this).val() != '0') {
$(this).remove();
}
$.ajax({
cache: false,
url: "my-url/_api/web/lists/GetByTitle('Deapartment')/items?$select=Title,Deapartment&$filter=Title eq '" + selectedValue + "'",
type: 'GET',
dataType: 'json',
async: false,
headers: {
"accept": "application/json;odata=verbose;charset=utf-8"
},
success: function (data) {
$.each(data.d.results, function (i, result) {
ItemDeapartmentDD = result.Deapartment;
$('#DeapartmentDD').append("<option value='" + ItemDeapartmentDD + "'>" + ItemDeapartmentDD + "</option>");
});
}, //end of success
error: function ajaxError(response) {
alert(response.status + ' ' + response.statusText);
},
}); //end of ajax
}); //end of each
} //end of function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment