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
    Aug 30 '12 at 10:35
  • i have alert(Title); its undefined will val() work in sharepoint Aug 30 '12 at 10:36
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
    Aug 30 '12 at 10:58
  • updated the answer Aug 30 '12 at 11:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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