1

So I'm trying to push through learning how to code in the SharePoint environment. I created a script in a text file that i'm calling through a content editor webpart. When I debug the page using FireBug in Firefox I get the following error.

"ReferenceError: AddItem is not defined"

from the default.aspx page in my SP site. Can someone point me in the right direction? Thanks. Below is my code.

<SharePoint:FormDigest runat=”server” />
<script src=”/_layouts/SP.js” type=”text/ecmascript”></script>
<script type=”text/javascript”>

function AddItem()
{
var context = new SP.ClientContext.get_current();
var web = context.get_web();
var list = web.get_lists().getByTitle(‘Test List’);

var listItemCreationInfo = new SP.ListItemCreationInformation();
var newItem = list.addItem(listItemCreationInfo);
newItem.set_item(‘Title’, ‘SPUser’);

newItem.update();
context.executeQueryAsync(Function.createDelegate(this, this.success),                Function.createDelegate(this, this.failed));
}
function success() {
alert(‘Added!’);
}
function failed(sender, args) {
alert(‘failed. Message:’ + args.get_message());
}

</script>

<div>
    <button type="button" onclick="AddItem()">Add List Item To SharePoint</button>
   </div>
2
  • 1
    try onclick="javascript:AddItem();"
    – Mike
    Sep 25, 2013 at 18:22
  • This isn't working in a content editor web-part. I'll try throwing it directly in the web page....Getting same error
    – Ghoztrider
    Sep 27, 2013 at 20:38

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.