I have a html table which holds some data and has a submit button at the bottom of the table.I am trying to save this data of table on button click to SharePoint 2010 list which is having same columns as table fields. How to follow for this kind of scenario to save table data to list.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
contactus Contact Information
Name:Company Name:
Email Address:
Phone Number:
Extension:
Comment:
<script type="text/javascript">
function submitValues() {
var Name = $('#fullName').val();
var CompanyName = $('#companyName').val();
var EmailAddress = $('#email').val();
var PhoneNumber = $('#area').val();
var Extension = $('#Text1').val();
var Comment = $('#comments').val();
createListItem(Name, CompanyName, EmailAddress, PhoneNumber, Extension, Comment);
}
function createListItem(Na, Cna, em, ph, ext, comm) {
var clientContext = new SP.ClientContext.get_current();
var oList = clientContext.get_web().get_lists().getByTitle('ContactUs');
var itemCreateInfo = new SP.ListItemCreationInformation();
var oListItem = oList.addItem(itemCreateInfo);
}
try {
oListItem.set_item('Title', 'HTML List item');
oListItem.set_item('Name', Na);
oListItem.set_item('CompanyName', Cna);
oListItem.set_item('EmailAddress', em);
oListItem.set_item('PhoneNumber', ph);
oListItem.set_item('Extension', ext);
oListItem.set_item('Comment', comm);
oListItem.update();
clientContext.load(oListItem);
clientContext.executeQueryAsync(
Function.createDelegate(this, this.onQuerySucceeded),
Function.createDelegate(this, this.onQueryFailed)
);
}
catch (err) {
alert(err);
}
//end function createListItem
function onQuerySucceeded() {
alert('Item Created: ' + oListItem.get_id());
}
function onQueryFailed(sender, args) {
alert('Request failed. ' + args.get_message() +
'\n' + args.get_stackTrace());
}
</script>