SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

So I usually only deal with server side code, and need some assistance. in c# i was able to just do something like,

numStirng = listItem["fieldName"].toString();
num = Convert.ToInt(num);
listItem["fieldName"] = num + 1;

heres my javascript code

 var selectedList = web.get_lists().getByTitle('Easy Poll');
            //var oListItem = selectedList.getItemById(parseInt("1", 10));
        var selectedItem = selectedList.getItemById(1);
                //selectedItem.get_item("EmployeeName", newName);

        selection = $('input[@name="food"]:checked').val();
        if(selection == "rubys")
             num = selectedItem[rubys];
            selectedItem[rubys] = num + 1;
        if(selection == "panda")
             num = selectedItem[panda];
            selectedItem[panda] = num + 1;
        if(selection == "subway")
             num = selectedItem[subway];
            selectedItem[subway] = num + 1;
        if(selection == "carls")
             num = selectedItem[carls];
            selectedItem[carls] = num + 1;


so my questions becoem a)what am I doing wrong? b)is there a good direction i can look to or is this an easy fix, ty.

share|improve this question
up vote 2 down vote accepted

From your code, I can see that you are trying to add/update new item.

Coding with the JavaScript Client Object Model can be tricky at first if you are coming from a C# background. Keep in mind that you have to "bring" objects to the client side before you can do your operations on them. This "bringing objects to the client side" is done by the ClientContext.load() and ClientContext.executeQueryAsync() methods.

Also, since operations in JavaScript are async, you have to make heavy use of call back functions.

Here are few basic operations with the JavaScript CSOM which should get your started:

Make sure to check all the How-To links on the left side.

Hope this helps.

share|improve this answer
THANK YOU, this helps so much – will Mar 5 '13 at 18:46

Your Answer


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.