1
<script src="../../../_layouts/Gridwebpart/jquery-1.6.3.js" type="text/javascript"></script>
<script src="../../../_layouts/Gridwebpart/jquery.SPServices-0.7.2BETA1.js" type="text/javascript"></script>
<SharePoint:FormDigest ID="FormDigest1"  runat="server" />
<script type="text/javascript">
    $(document).ready(function () {

        //GetKeywordList();
    });
    function AddNewSPListItem() {
        alert($('#<%=txtName.ClientID %>').val());
        var Title = $('#<%=txtName.ClientID %>').val();
        var Description = $('#<%=txtDescription.ClientID %>').val();
        alert(Title);
        $().SPServices({
            operation: "AutocompleteKeywordList",
            async: false,
            webURL: window.location.protocol + "//" + window.location.host,
            listName: "GridList",
            updates: "<Batch OnError='Continue' PreCalc='TRUE'>" +
            //Cmd = 'New' is a command to add new record in the list.
                       "<Method ID='1' Cmd='New'>" +
                       "<Field Name='TopNumber'>1</Field>" +
                       "<Field Name='Title'>" + Title + "</Field>" +
                       "<Field Name='Description'>" + Description + "</Field>" +
                       "</Method>" +
                       "</Batch>",
            completefunc: function (xData, Status) {
                alert("success");
            }
        });      //End SPSErvices
    }
    </script>

ERROR

have alert(Title); its undefined will val() work in sharepoint

2
  • whats the error ?
    – Learner
    Commented Aug 30, 2012 at 10:35
  • i have alert(Title); its undefined will val() work in sharepoint Commented Aug 30, 2012 at 10:36

1 Answer 1

0
 function AddNewSPListItem() {
alert($('#<%=txtName.ClientID %>').val());
var Title = $('#<%=txtName.ClientID %>').val();
var Description = $('#<%=txtDescription.ClientID %>').val();
alert(Title);
$().SPServices({
operation: "UpdateListItems",
async: false,
webURL: window.location.protocol + "//" + window.location.host,
listName: "GridList",
updates: "<Batch OnError='Continue' PreCalc='TRUE'>" +
//Cmd = 'New' is a command to add new record in the list.
"<Method ID='1' Cmd='New'>" +
"<Field Name='Title'>" + Title + "</Field>" +
"<Field Name='Description'>" + Description + "</Field>" +
"</Method>" +
"</Batch>",
completefunc: function (xData, Status) {
alert("success");
}
}); //End SPSErvices
} 

EXPLAINATION: There was no fieldname called "Field Name='TopNumber'>1 Field" + So the whole operation was failing.

Also instead of operation: "AutocompleteKeywordList", it should be operation: "UpdateListItems",

2
  • can you explain what was the problem with code in question plss
    – Learner
    Commented Aug 30, 2012 at 10:58
  • updated the answer Commented Aug 30, 2012 at 11:02

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.