I am trying to updating List Items using JSOM on a sharepoint online site.
However I get error as below:
Home.aspx:991 Uncaught SyntaxError: Unexpected token {Home.aspx:1068 Uncaught SyntaxError: Unexpected token {
init.js:1 Exception while trying to access stylesheet rules: SecurityError: Failed to read the 'cssRules' property from 'CSSStyleSheet': Cannot access rules
Home.aspx:903 Uncaught ReferenceError: listitem is not defined
at HTMLInputElement.UpdateItems (Home.aspx:903)
at HTMLInputElement.handle (jquery.min.js:55)
at HTMLInputElement.o (jquery.min.js:49)
Can someone assist on this please?
script:
===========
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script><script language="javascript" type="text/javascript">
$(document).ready(function ()
{
$('#updatebtn').click(UpdateItems);
});
function UpdateItems(itemID)
{
var title= $("#title").val();
var empnameval= $("#empname").val();
var empidval= $("#empid").val();
var siteurl = 'https://xyz.sharepoint.com/sites/abc/';
var clientContext = new SP.ClientContext(siteurl);
var web = clientContext.get_web();
var list= clientContext.get_web().get_lists().getByTitle('List MMS');
var listItemCreationInformation = new SP.ListItemCreationInformation();
var listitem = list.addItem(listItemCreationInformation);
listitem.set_item('title', +title);
listitem.set_item('empname',+empnameval);
listitem.set_item('empid',+empidval);
listitem.update();
clientContext.load(listitem);
clientContext.executeQueryAsync(
Function.createDelegate(this, this.onQuerySucceeded),
Function.createDelegate(this, this.onQueryFailed)
);
}
function onQuerySucceeded() {
alert('List item has been updated');
}
function onQueryFailed(sender, args) {
alert('Request failed. ' + args.get_message() +
'\n' + args.get_stackTrace());
}
</script>
<table>
<tr>
<td>Title</td>
<td><input type="text" id="title" name="title"</td>
</tr>
<tr>
<td>Employee name:</td>
<td><input type="text" id="empname" name="empname"</td>
</tr>
<tr>
<td>EmployeeId:</td>
<td><input type="text" id="empid" name="empid"</td>
</tr>
<tr>
<td><input type="button" id="updatebtn" value="Update"</td>
</tr>
</table>