Trouble with Update List Items

Dec 27, 2010 at 11:29 PM

I'm sure I'm missing something simple, but I'm having trouble figuring out what that is. I am trying to insert values from a simple form to a list, but no items are getting populated. I have verified that the list exists, and that I have permission to write to it.

 
<script type=text/javascript src="../webelements/js/jquery-1.4.4.min.js"></script>
<script type=text/javascript src="../webelements/js/jquery.SPServices-0.5.8.js"></script>
<script type=text/javascript>         
         function CreateNewItem(subject, message) { 
          $().SPServices({
           operation: "UpdateListItems",
           async: false,
           batchCmd: "New",
           webURL: "http://express/jwresourcetracker/pages/test",
           listName: "Test",
           valuepairs: [["Title", subject], ["Message", message]],


           completefunc: function(xData, Status) {
             alert(xData.responseText);
             alert(xData.responseXML.xml);
             alert("completed");
           }
          }) 
         ;}
                   

          $(document).ready(function() {
          $("#newTaskButton").click(function() {
            alert("yes"); 
           //var subject = $("#feedback-subject-input input").val();
           //var message = $("#message input").val();
           var message = "message";
           //var subject = $("subject input").text();
           var subject = "subject";
           CreateNewItem(subject, message);  
         
          });
         });
        </script>

	<input id="message" type="text" name="message" value="message"/>
	<input id="subject" type="text" name="subject" value="subject"/>	
	<input id="newTaskButton" type="button"  style="vertical-align:middle;font-size:11px;font-family:verdana" name="Submit" value="Submit" />
Cheers,
Jason
Coordinator
Dec 28, 2010 at 2:36 AM
Edited Dec 28, 2010 at 2:36 AM

Jason:

What are you getting back from alert(xData.responseText);? My guess is that webURL: http://express/jwresourcetracker/pages/test isn't valid, since it looks like you're pointing to the pages Document Libary. The webURL should point to the site where the list resides. (If the list is in the current site, then there's no need to specify it.)

M.

Dec 28, 2010 at 4:29 AM

Marc,

    I was able to get the events to fire after removing the webURL reference. I am able to pull information from the Message text box. The Subject text box causes an undefined error to be displayed. Great work on the Services Library.

$(document).ready(function() {
          $("#newTaskButton").click(function() {
            alert("Request Submitted"); 
           //var subject = $("#feedback-subject-input input").val();
           var message = $("#message").val();
           //var message = "message";
           var subject = $("subject input").val();
           CreateNewItem(subject, message);  
         
          });
         });

Jason

Coordinator
Dec 28, 2010 at 4:31 AM

Jason:

var subject = $("subject input").val();

should probably be something more like:

var subject = $("input#subject").val();

which would mean an input element with id="subject".

M.

Dec 28, 2010 at 8:19 PM

Marc,

     It worked, thank you for taking the time to help! Is there a reference I can use for working with the different types of fields?

 

Jason

Coordinator
Dec 28, 2010 at 8:25 PM

Not to be coy, but the jQuery site itself is excellent. If you understand CSS selectors, then you'll understand jQuery selectors better, too. There are also some good books, though I haven't read any of them!

M.