Add item to list using JavaScript client object model in SharePoint 2013/2016/Online

This JSOM SharePoint tutorial explains, how to add an item to a SharePoint 2013/2016/Online list using the JavaScript object model (jsom).

In this example, we will provide an option for the user to enter the title for the item and the user can click on the button to save the item into a SharePoint list.

You can also read how to add an item to the SharePoint list using PowerShell.

Add item to list using JavaScript client object model (jsom) in SharePoint

Here I have a SharePoint list and I want to insert an item to that list. We will write the code in a script editor web part.

<script type="text/javascript">
function insertitemtolist()
{
var title=document.getElementById('txtTitle').value;
var clientContext = new SP.ClientContext("http://win-pfcp2dgt8di/sites/EnjoySharePoint/");
var oList = clientContext.get_web().get_lists().getByTitle('TestList');
var item = new SP.ListItemCreationInformation();
var oListItem = oList.addItem(item);
oListItem.set_item('Title', title);
oListItem.update();
clientContext.load(oListItem);
clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));
}
</script>
Enter Item Title: <input type="text" id="txtTitle" /> <br/><br/>

<button type="button" onclick="insertitemtolist();">Insert Item To List</button>

You may like following jsom SharePoint tutorials:

Hope this SharePoint tutorial helps to learn a simple way to insert item to a SharePoint Online list using jsom.

Donwload Hub site pdf

Download SharePoint Online Tutorial PDF FREE!

Get update on Webinars, video tutorials, training courses etc.

>