ECMA Script : To update SharePoint 2010 list item

 

<script language="ecmascript" type="text/ecmascript">

 

    var clientContext = null;

    var oWeb = null;

    var oListColl = null;

    var oList = null;

    var oListItem = null;

   

  

 

    function updateListItem() {

        clientContext = new SP.ClientContext.get_current();

        oWeb = clientContext.get_web();

        oListColl = oWeb.get_lists();

        oList = oListColl.getByTitle('Custom List');     

        oListItem = oList.getItemById(1);

        oListItem.set_item('Title', 'Item Updated');

        oListItem.update();        

        clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));

    }

 

    function onQuerySucceeded() {

 

        alert('item is updated successfully.');

    }

 

    function onQueryFailed(sender, args) {

        alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());

    }

 

 

 

</script>

<input id="btnUpdateListItem" onclick="updateListItem()" type="button" value="Update List Item"/>