Get the choices from a choice field using javascript client object model
Hi How To get the choice field values from javascript client object model.I know That it can be done through client object model but is it possible to get choices using ecma script
July 15th, 2011 6:09am

Please tell the way get the choice field values using client object model that you know. i tried but cant meet the solution.
Free Windows Admin Tool Kit Click here and download it now
July 20th, 2011 9:23am

Hi shashidar,

 

To get the choice field values from client object model, please refer to:

http://www.learningsharepoint.com/2010/07/24/get-choice-field-values-using-client-object-model-sharepoint-2010/

 

Thanks,

Simon

July 22nd, 2011 5:46am

OK I have two points to make on the marked answer.

  1. It points to an unofficial source.
  2. The code is just plain wrong. Have you tried it?
Free Windows Admin Tool Kit Click here and download it now
August 6th, 2014 3:42am

you can get the options of choice field usin below code..

//length of array---_all[0].Choices.results.length

$(document).ready(function() {
try {
    jQuery.ajax({
        url: _spPageContextInfo.webAbsoluteUrl + "_api/web/lists/GetByTitle('listname')/fields?$filter=TypeDisplayName eq 'Choice'",
        type: "GET",
                async: false,
                headers: { "Accept": "application/json;odata=verbose" },
                dataType: "json",
        success: function (data) {
            _all = data.d.results;
            fillchoices(_all);
            //alert('yes');
            //alert(_all[0].Id);
            //option value for the first choice column
            for(var f=0;f<_all[0].Choices.results.length;f++)
          {
           alert(_all[0].Choices.results[f]);    
           }
           // if your list having more than one choice column then you can use _all[1].Choices.results[f] i.e. increase the _all array by 1 to move to the next choice field.
            
        },
        error: function (data) {
            console.log(JSON.stringify(data));
            alert('no');
        }
    });
    }
     catch (ex) {
            console.log(ex.message);
        }
        });

June 2nd, 2015 12:57am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics