Created
March 4, 2015 15:57
-
-
Save nilayparikh/3ea7f9529bf0958c57fd to your computer and use it in GitHub Desktop.
Populate dropdown from SharePoint Site (JSOM)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<select name="departmentDD" title="department" id="departmentDD" onchange="populateDeapartment(this.value)"> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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