0

I am working on page where there are 5 fields in a field set . Now , I want to giv Id to a particular field in Field set and want to use $Component to get the field and run some Javascript function. Unfortunately, there is field set not the field. how can I provide ID to the field in the field set and use document.getElementById on that field to run Javascript function on it

1 Answer 1

0

I don't think you can control the ID values. I suggest that instead you use the class of the elements to find them.

Here is an example:

<apex:page standardController="Contact">
    <apex:form>
        <apex:repeat value="{!$ObjectType.Contact.FieldSets.Test}" var="f">
            <apex:inputField value="{!Contact[f]}" styleClass="{!f}"/>
        </apex:repeat>
    </apex:form>
<script>
function firstOfClass(className) {
    var els = document.getElementsByClassName(className);
    return els.length > 0 ? els[0] : null;
}
alert(firstOfClass('AssistantName').tagName);
</script>
</apex:page>

In this example I have a field set called "Test" defined that includes the field "AssistantName". You could include a loop counter value in the class name instead if you wanted the logic to work by index rather than field name.

The class does not have any CSS associated; it is just being used to mark the element so that the element can be found.

You must log in to answer this question.

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