In SharePoint Online site, I have created Employees list, which contains all the emails.
I have created one more list in which I have created a single line of text field named Email in which autocomplete functionality is implemented.
On newitem.aspx, add a content editor Webpart and add the code snippet given below.
- <link rel="stylesheet" href="/sites/vijai/SiteAssets/autocomplete/jquery-ui.css"/>
- <script type="text/javascript" src="/sites/vijai/SiteAssets/autocomplete/jquery-ui.js"/>
- <script type="text/javascript" src="/sites/vijai/SiteAssets/autocomplete/jquery-1.11.0.min.js"/>
- <script type="text/javascript" src="/_layouts/15/init.js"></script>
- <script type="text/javascript" src="/_layouts/15/sp.runtime.js"></script>
- <script type="text/javascript" src="/_layouts/15/sp.js"></script>
- <script type="text/javascript">
- var clientContext;
- var website;
- var array = [];
- // Make sure the SharePoint script file 'sp.js' is loaded before your code runs.
- SP.SOD.executeFunc('sp.js', 'SP.ClientContext', getAutoComplete);
- function getAutoComplete() {
- clientContext = SP.ClientContext.get_current();
- var oList = clientContext.get_web().get_lists().getByTitle("Employees");
- var camlQuery = new SP.CamlQuery();
- camlQuery.set_viewXml("<View><RowLimit>100</RowLimit></View>");
- collListItem = oList.getItems(camlQuery);
- clientContext.load(collListItem);
- clientContext.executeQueryAsync(onRequestSucceeded, onRequestFailed);
- }
- function onRequestSucceeded() {
- var listItemInfo = "";
- var listItemEnumerator = collListItem.getEnumerator();
- while (listItemEnumerator.moveNext()) {
- var oListItem = listItemEnumerator.get_current();
- sArray.push(oListItem.get_item("Title"));
- }
- $("input[title='Email']").autocomplete({ source: array });
- }
- function onRequestFailed(sender, args) {
- alert('Error: ' + args.get_message());
- }
- </script>
Result
Reference
https://jqueryui.com/autocomplete/
Summary
In this blog, you have seen how to implement textbox autocomplete functionality, using jQuery in SharePoint Online.

pp rrPosted Feb 8, 2021, 3:36 AM
Please remove this line $("input[title='Email']").autocomplete({ source: array }); then add $("#autocompleteTextBox").autocomplete({ source: sarray }); then Title: <input id="autocompleteTextBox" type="text" />
pp rrPosted Feb 8, 2021, 3:35 AM
Please remove this lin
pp rrPosted Feb 8, 2021, 3:35 AM
This is working for me
KamnaPosted Apr 26, 2018, 12:24 AM
Hi Vijai - I have created two lists as you have suggested above. First list with Employees name and second anything (no specific name as it is not used anywhere in your code I believe). The following JS and CSS libs are being used in my code <link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/themes/smoothness/jquery-ui.css"><script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script> <script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script> however this code is not working. Any thoughts on thi??
KamnaPosted Mar 16, 2018, 12:21 AM
This code is not working for me on SharePoint online. I created the two lists with same names and columns for testing the code and it is not working. I have checked the the last three scripts are already present on my site. Can you please let me know the solution.<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/themes/smoothness/jquery-ui.css"><script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script> <script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script> <script type="text/javascript" src="/_layouts/15/init.js"></script> <script type="text/javascript" src="/_layouts/15/sp.runtime.js"></script> <script type="text/javascript" src="/_layouts/15/sp.js"></script> <script type="text/javascript"> var clientContext; var website; var array = []; // Make sure the SharePoint script file 'sp.js' is loaded before your code runs. SP.SOD.executeFunc('sp.js', 'SP.ClientContext', getAutoComplete); function getAutoComplete() { clientContext = SP.ClientContext.get_current(); var oList = clientContext.get_web().get_lists().getByTitle("Employees"); var camlQuery = new SP.CamlQuery(); camlQuery.set_viewXml("<View><RowLimit>100</RowLimit></View>"); collListItem = oList.getItems(camlQuery); clientContext.load(collListItem); clientContext.executeQueryAsync(onRequestSucceeded, onRequestFailed); } function onRequestSucceeded() { var listItemInfo = ""; var listItemEnumerator = collListItem.getEnumerator(); while (listItemEnumerator.moveNext()) { var oListItem = listItemEnumerator.get_current(); sArray.push(oListItem.get_item("Title")); } $("input[title='Email']").autocomplete({ source: array }); } function onRequestFailed(sender, args) { alert('Error: ' + args.get_message()); } </script>