function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
JasonGablerJasonGabler 

Get the id of a rendered VisualForce inputField?

In the code below I place a custom id of primary_contact_phone into the inputField.  When the form field is rendered, the actual markup id is "j_id0:rfq_form:j_id7:primary_contact_phone".  I have some complicated styling to do and I want to create my own <label>s, instead of using the built-in blockSection labels.  So when using the "for" attribute, I want to do <label for="primary_contact_phone">.  Of course, that does not work, I need to have <label for="j_id0:rfq_form:j_id7:primary_contact_phone">.  But this is rendered by Salesforce and I do not know what it will be.  I have been trying to access the id with attempts like  {!$Component.rfq_form.primary_contact_phone}.  I've also been reading on how to access IDs for using with Javascript in the VF reference, and I've done this before.  But I cannot seem to get that darn ID.  Any ideas on how to properly get the ID of the input field?

 

 

 

<apex:page cache="false" sidebar="false" showHeader="false" standardController="RFQ__c">

    <apex:form id="rfq_form">

        <apex:inputField value="{!RFQ__c.primary_contact_phone__c}" id="primary_contact_phone"/>

        ....

    </apex:form>

</apex:page>

 

thanks,

jyg

jwetzlerjwetzler

The {!$Component} example you posted should work just fine, not sure why it's not for you...  where are you trying to put this label, right next to your inputField?

 

But try using apex : outputLabel, that should wire things up properly.  You should just be able to do for="primary_contact_phone"

BeeddiskShahBeeddiskShah

The best solution i can suggest is, you give ids to all the tags before your element. This way you can fetch your name in chain...

 

id1:id2:id3 etc

SteveBowerSteveBower

Shouldn't it be:  {!$Component.primary_contact_phone}.

 

(without the Form id?) 

 

(However I also yield to Jill's response which seems right, especially regarding: for="primary_contact_phone"... :-)  )

 

Best, Steve.

jwetzlerjwetzler

it doesn't really hurt to qualify $Component with the container id.  depending on the placement of $Component, it may actually be a requirement.  that's why I asked for the location of the label field.