Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.
<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

share|improve this question
    
whats the error ? –  yuri kilochek Aug 30 '12 at 10:35
    
i have alert(Title); its undefined will val() work in sharepoint –  Rajesh Chowdary Aug 30 '12 at 10:36
add comment

1 Answer

up vote 0 down vote accepted
 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",

share|improve this answer
    
can you explain what was the problem with code in question plss –  yuri kilochek Aug 30 '12 at 10:58
    
updated the answer –  Ashirvad Singh Aug 30 '12 at 11:02
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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