Updating single items is list using SPservices

Daniel Ellison picture Daniel Ellison · Apr 21, 2015 · Viewed 8.3k times · Source

I've been struggling to learn how to use SPservices. What I am trying to accomplish is creating a simple input button that will update my item on my list automatically and refresh my page.

Now where I am getting confused here is that the field I am trying to update is an input box (plain text basically). Users would add their dates on that input box manually in this format 03/09/2015 20:48 (MM/DD/YYYY HH:MM). I want to add that button for each item on that row, so that when a user clicks on it, it calculates the current time and adds an extra hour.

I scavenged the web for similar situation as mine but cant seem to get any examples to work with. Just looking for some help, advice, pointers anything at this point.

$().SPServices({
    operation: "UpdateListItems",
    listName: "List Name",
    ID: ID,
    valuepairs: valuePairs,
    completefunc: function(xData, Status) {
        //Callback
    }
});

Answer

Daniel Ellison picture Daniel Ellison · Apr 24, 2015

Figured it out, i created a new column and added the item's ID to it and put the row's TD as display: none;. This would essentially hide but with javascript I can still get its information. I then created another column with my button and gave the class update_button and its working great now.

I know this isnt exactly what I said I wanted but this solves a big portion of this puzzle. Hope this helps someone.

<script language="javascript" type="text/javascript">
$(document).ready(function() {
    $(".update_button").click(function() {
    var id = $(this).closest("tr").find(".hidden_ID").text();
        $().SPServices({
            operation: "UpdateListItems",
            async: false,
            batchCmd: "Update",
            listName: "Severities",
            ID: id,
            valuepairs: [["Notes", "Updated"]],
            completefunc: function (xData, Status) {
            alert(id);
        }
    });
});
});
</script>