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