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
JeegarJeegar 

How to set Id parameter for Apex insert Tag

I am trying to refer to a component using document.getElementById which is includede by apex:insert tag. The problem is I am not having control over specifying Id for the Insert tag, which salesforce assigns randomly when page renders.

 

Below is the sample code, I am not able to get reference of  "idLabelTag".

 

    <apex:insert name="header">
            <c:BIBheader />
    </apex:insert>

<apex:component id="BIBheader">

        <apex:outputLabel  id="idLabelTag" >800 888 1111</apex:outputLabel>

</apex:component>

 

Is there something I can do to fix this?

imuinoimuino

First of all i recommend you to use a JavaScript library such as jquery, it makes things easier.

But you can put a div around the the tag with a new id. Then you select the div by its id, and select the insert tag as a child of it with firstChild() in JavaScript

sforce2009sforce2009

Here is the code

Page:

<apex:page >
<apex:form>
    <apex:insert name="header">
            <c:BIBheader id="testId"/>
    </apex:insert>
    <script>
    var obj = document.getElementById("{!$Component.testId}:BIBheader:idLabelTag");
    var Id = "{!$Component.testId}:BIBheader:idLabelTag";
    alert("-------id is--------" + Id + "--------value Is---------" + obj.innerHTML);

    </script>
 </apex:form>
</apex:page>


Component:

<apex:component id="BIBheader">

        <apex:outputLabel  id="idLabelTag" >800 888 1111</apex:outputLabel>

</apex:component>

 

Cheers.