Skip to content

Instantly share code, notes, and snippets.

@Microsofttechies
Last active September 11, 2016 04:50
Show Gist options
  • Select an option

  • Save Microsofttechies/acd95a15df73f23f2fca72b82d39e44c to your computer and use it in GitHub Desktop.

Select an option

Save Microsofttechies/acd95a15df73f23f2fca72b82d39e44c to your computer and use it in GitHub Desktop.
SharePoint Online Pull values from a lookup column using SPServices()
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.SPServices/2014.02/jquery.SPServices.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
</head>
<script>
$(document).ready(function () {
//With out ID
$().SPServices({
operation: "GetListItems",
async: false,
listName: "Country",
CAMLViewFields: "<ViewFields><FieldRef Name='Title'/></ViewFields>",
completefunc: function (xData, Status) {
$(xData.responseXML).SPFilterNode("z:row").each(function () {
var liHtmlbi = "<option><a href='#' title=''>" + $(this).attr("ows_Title") + "</a></option>";
$("#country").append(liHtmlbi);
});
}
});
//With ID
$().SPServices({
operation: "GetListItems",
async: false,
listName: "Country",
CAMLViewFields: "<ViewFields><FieldRef Name='ID'/><FieldRef Name='Title'/></ViewFields>",
completefunc: function (xData, Status) {
$(xData.responseXML).SPFilterNode("z:row").each(function () {
var liHtmlbi = "<option value='" + $(this).attr("ows_ID") + "'>" + $(this).attr("ows_Title") + "</option>";
$("#country").append(liHtmlbi);
});
}
});
});
</script>
<body>
<table>
<tr><td>Country</td><td><select id="country" style="max-width:90%;"></select></td></tr>
</table>
</body>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment