/    Sign up×
Community /Pin to ProfileBookmark

How to submit text data to SharePoint list using JavaScript or jQuery?

I’ve looked at and tried doznes of “examples” online but after reading the comments for those examples, I find that I’m not the only one that can’t get them to work.

I’m looking for some examples on how to submit data from textboxes to a Sharepoint list onbuttonclick and how to read data onbuttonclick.

Anyone here know how? I’m working with the content editor web part in SharePoint and have tried all kinds of libraries, even putting the code in a js file but never works.

to post a comment
JavaScript

12 Comments(s)

Copy linkTweet thisAlerts:
@lenovoauthorNov 19.2015 — Bump.
Copy linkTweet thisAlerts:
@Kevin2Nov 19.2015 — Something that confounds me is when folk ask a question on a general interest forum about how to build or do something using proprietary software and expect an answer to their question. My guess is that less than 0.0001% of members here (i.e. you're the only one) use SharePoint. Why not ask, or search for, your question on the SharePoint forum and get a valid answer from the "horse's mouth"?

https://social.msdn.microsoft.com/Forums/sharepoint/
Copy linkTweet thisAlerts:
@lenovoauthorNov 19.2015 — lol, I already did. There are a few others who have already asked on there, there were some of the examples that came up in a variety of different search results, from different sites. I even posted that none of the examples I found worked, and that I found other threads of people with the same problem but no resolution. SOMEBODY out there has done this, I just figured since I wasn't getting results on one forum, I would try another.
Copy linkTweet thisAlerts:
@Kevin2Nov 19.2015 — ??

Well, it was a thought. Unfortunately I have no other advice.
Copy linkTweet thisAlerts:
@lenovoauthorNov 19.2015 — I'll keep looking. Somebody out there has surely has an accurate blog about this. Thus far it's been mostly a bunch of stuff that doesn't work, and in some threads, I've noticed even others complained that they can't get MS's examples on technet to work as is.
Copy linkTweet thisAlerts:
@benmartin101Nov 19.2015 — Question, do you know how to submit data to Sharepoint list (outside of javascript/jquery)? Maybe like REST, etc.?
Copy linkTweet thisAlerts:
@lenovoauthorNov 19.2015 — I can do it via XML based infoPath forms (which also can use SOAP/REST Web services) and a couple other means that don't involve coding, however; for some applications I need to be able to have more flexibility than is provided in the above means.
Copy linkTweet thisAlerts:
@benmartin101Nov 20.2015 — If you are able to use REST web service, then your only issue is calling that REST web service using javascript?
Copy linkTweet thisAlerts:
@bgarver02Nov 20.2015 — Checkout SPServices
Copy linkTweet thisAlerts:
@shredder123Nov 20.2015 — Sorry for the irrelevancy but i am in an urgent need of help. I basically need some info on how to make lots of 100x100 boxes in my website where people can click on them and insert whatever image or gif they want. I am obviously a rookie at this and any help is definitely appreciated. Also what program is best to do this on? Thanks guys and sorry once again.
Copy linkTweet thisAlerts:
@lenovoauthorNov 25.2015 — Shredder, what platform are you developing on? I checked your thread on this and didn't see it. If it is SharePoint I can help you out with that. Basically I would create a web part page filled with content editor web parts that users can add their own images to.

In any case, hope you got help with what you were trying to do. In regards to the original thread topic, here is some code I was graciously provided that actually works for submitting items to SharePoint via code. I really like this solution as it doesn't require a URL, that needs to be updated every time the server farm is upgraded to a new version, migrated somewhere else, etc. Since it just uses the list name, it never needs to be updated unless the list name is manually changed:


<script src="https://code.jquery.com/jquery-1.10.2.js"></script>

<script type="text/javascript">

var clientContext;

var currentUser;

var targetWeb;

var text1;

var text2

// When the body is loaded, the onload event handler executes each function whose name is contained in this array.

_spBodyOnLoadFunctionNames.push("callCSOM");

function callCSOM()

{

$("#Button1").click(function()

{

// Make sure the SharePoint script file 'sp.js' is loaded before your code runs.

text1 = $('#TextBox1').val();

text2 = $('#TextBox2').val();

ExecuteOrDelayUntilScriptLoaded(sharePointReady, "sp.js");

});

}

function sharePointReady()

{

addListItems();

}


function addListItems()

{

// Create an instance of the current context to return context information

clientContext = SP.ClientContext.get_current();

var oList = clientContext.get_web().get_lists().getByTitle('testlist');

//Initializes a new instance of the SP.ListItemCreationInformation Class
var itemCreateInfo = new SP.ListItemCreationInformation();

//Creates a new list item in the list
this.newListItem = oList.addItem(itemCreateInfo);

//Sets the specified field value
newListItem.set_item('Title', "Title");
newListItem.set_item('TextBox1', text1);
newListItem.set_item('TextBox2', text2);
//Commits changed properties of the list item
newListItem.update();
clientContext.load(newListItem);

//Executes the current pending request asynchronously on the server
clientContext.executeQueryAsync(onRequestSucceeded, onRequestFailed);

}

//the delegate of the method that is called when the request is executed successfully

function onRequestSucceeded()

{

alert("Submit data successfully");

}

//the delegate of the method that is called when the request is executed unsuccessfully

function onRequestFailed(sender, args)

{

alert('Error: ' + args.get_message());

}

</script>

<input id="Button1" type="button" value="Run Code"/>

<input id="TextBox1" type="text"/>

<input id="TextBox2" type="text"/>




































40 Points



[/QUOTE]
Copy linkTweet thisAlerts:
@vinborisMar 28.2017 — SharePoint allows businesses to submit proposals and work on the documents together, with a great ease! Here are the

3 Amazing Things You Probably Didn&#8217;t Know About SharePoint, why it is so useful. http://web-development-solution.weebly.com/web-development-services/3-amazing-things-you-probably-didnt-know-about-sharepoint
×

Success!

Help @lenovo spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.29,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...