I am trying to show a selectlist in a visualforcepage populated with picklist values (from field say pickField__c) on a custom object (say object__c) using only javascript. I know how to achieve this using a controller method with getDescribe().getPickListValues() but I wanted to do this exclusively using javascript. Is there a way to achieve this?


1 Answer 1


Your page would look something like this:

    <apex:includeScript value="/soap/ajax/31.0/connection.js"/>
    <select id="yourSelect">

        sforce.connection.sessionId = '{!$Api.Session_ID}'; 
        //Global Object
        var describeResults = sforce.connection.describeSObject("Account");
        //select option list
        var select = document.getElementById("yourSelect");
        for(var i = 0; i < describeResults.fields.length; i++) { 
            var fieldList = describeResults.fields[i];   

            if (fieldList.label == 'Industry') {
                var values = fieldList.picklistValues;
                for(var j = 0; j <values.length; j++) { 
                    var el = document.createElement("option");
                    el.textContent = values[j].label;
                    el.value = values[j].value;


This example uses the Account object and the Industry field, but you should be able to adapt for any object.

There may be a better way to access the field that you are interested in, but so far I haven't found it yet.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .