.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Home >> Code Snippets >> SharePoint >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Sharepoint:Add list item Custom list: ECMA Script Client Object Model.

Posted By:Sagar Pardeshi       Posted Date: November 11, 2013    Points: 40    Category: SharePoint    URL: http://www.dotnetspark.com  

We have Add item in sharepoint Custom List using ECMA Script Client Object Model.

<Sharepoint:ScriptLink name="SP.js" runat="server" OnDemand="true" localizable="false" />

<input type="text" id="txtiem" />
<input type="button" id="btnitem" onclick="AddItem();" value="Add New Item" />
<label id ="lbl" runat="server"/>

<script type="text/ecmascript">
function AddItem() {
var txtItem = document.getElementById("txtiem");
if (txtItem.value == "") {
alert("please enter");
//Retrieve the clientContext
var clientContext = SP.ClientContext.get_current();
//Retrieve the current website
var webSite = clientContext.get_web();
//Retrieve the lists
var lists = webSite.get_lists();
//Get the List
var carsList = lists.getByTitle("Lststmay");
//Create new IteamCreationInformation
var itemCreationInfo = new SP.ListItemCreationInformation();
//the addItem takes the itemCreationInformation object
//and returns the listItem
var listItem = carsList.addItem(itemCreationInfo);
//Set the title of the list Item
//to the value in the text
listItem.set_item("Title", txtItem.value);
listItem.set_item("Name", "Xyz");
//Call Update the listItem
//Finally execute the operation
//pass to it a 2 callBack methods OnSucceed and OnFailure

function Succeeded() {
function Failed(sender,args) {


Further Readings:


No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend