Prasad Bolla's SharePoint Blog

Click Here to go through the Interesting posts within my Blog.

Click Here to go through the new posts in my blog.

Tuesday, October 09, 2012

Insertion into SharePoint List using ECMA Script

 

Note:-
Use AddItem() Function in Button Onclick event.

function AddItem()
{
                ExecuteOrDelayUntilScriptLoaded(NewItems, "sp.js");
}


function NewItems()
{
                try
                {
                var context = new SP.ClientContext.get_current();
    var web = context.get_web();
    var list = web.get_lists().getByTitle('Login');
    var listItemCreationInfo = new SP.ListItemCreationInformation();
    var newItem = list.addItem(listItemCreationInfo);
                newItem.set_item('Title', document.getElementById("txtUserName").value);
                newItem.set_item('Password', document.getElementById("txtPassWord").value);
                newItem.update();
    context.executeQueryAsync(Function.createDelegate(this, this.onSuccessMethod), Function.createDelegate(this, this.onFailureMethod));
    }
    catch(ex)
    {
                alert(ex.message);
    }
}

function onSuccessMethod()
{
                alert('Record Saved Successfully');
                document.getElementById("txtUserName").value="";
                document.getElementById("txtPassWord").value="";
}
function onFailureMethod(sender, args)
{
                alert('failed. Message:' + args.get_message());
}

No comments:

Post a Comment