Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

When my user clicks a button, I want to access the fieldset by javascript. Can i do that?

  <apex:commandbutton value="Send"  onClick="check('{$ObjectType.Customization__c.FieldSets.Fields_for_fieldChooser}')" />


    function check(apiNameList) {

        for (var i = 0; i < apiNameList.length; i++) {
            var apiName = apiNameList[i];

            var updateVal = apiName + "_update";
            var deleteVal = apiName + "_delete";
            var dontaddVal = apiName + "_do_not_add";
            //    if ( document.getElementById(updateVal).checked === false && document.getElementById(deleteVal).checked === false && document.getElementById(dontaddVal).checked === false){
            alert("Please choose an option for each field");

            //     }

share|improve this question

1 Answer 1

up vote 3 down vote accepted

To get quotes round the field names so you have a JavaScript array of strings, you need to turn the Apex array into a JavaScript array by for example using an apex:repeat:

var fields = [
<apex:repeat var="f" value="{!$ObjectType.Customization__c.FieldSets.Fields_for_fieldChooser}">

The above Visualforce produces this:

var fields = [
   ' Field3__c',

Then adapt you other JavaScript to reference this array. (Note that the spurious trailing comma is allowed in JavaScript).

Or if you need the JavaScript arrays to be inline, this will work:

... onClick="check([<apex:repeat var="f" value="{!$ObjectType.TestRelationship__c.FieldSets.TestFieldSet}">'{!f}', </apex:repeat>])" ...
share|improve this answer

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.