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
coolKarnicoolKarni 

Getting the id dynamically

Hi, How can i catch the id of a label which is inside a pageblocktable.

I am to that using the id as

document.getElementById('j_id0:form:pageBlock:pageBlockTable:0:label');

 

 

but the issue with this is that i can access only one value when clicked on a link which is at 1st Row. how can i access the value of a label when clicked on the link which is on Nth row??.

 

Here is my code:

 

<apex:page sidebar="false" showHeader="false" controller="ChildPopup">
<script type="text/javascript">
function closePopup()
{
var label = document.getElementById('j_id0:j_id2:j_id3:j_id4:0:label');
 alert(label.innerHTML);
window.parent.opener.document.getElementById('j_id0:j_id1:pageBlock:section:contractNo').value= var winMain = window.opener;
if(null == winMain)
{
    winMain = window.parent.opener;
}
winMain.closePopup1();
}
</script>
<apex:form id="form">
<apex:pageBlock id="pageBlock" title="Contract Number">


<apex:pageBlockTable id="pageBlockTable" value="{!accDetails}" var="acc" >
<apex:column id="column">
<apex:outputLink id="outputLink" onclick="return closePopup();" >
<apex:outputLabel id="label" value="{!acc.Contract_Number__c} "></apex:outputLabel>
</apex:outputLink>
</apex:column>
</apex:pageBlockTable>


</apex:pageBlock>

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

 

 

I laso tried using  as : document.getElementById('{!$Component.form.pageBlock.pageBlockTable.column.outputLink.label}')

 

Please help me out!

 

Thanks

 

bob_buzzardbob_buzzard

Can you not just pass it to the method, i.e.

 

<apex:smileysurprised:utputLink id="outputLink" onclick="return closePopup(this.id);" > 

jwetzlerjwetzler

Yeah, $Component is what you want to use, and you need to pass it into your javascript function.  $Component gets a little confusing because its behavior depends on its location, which you probably know.  If you use it to return the id of something in the columns of your table, it will return the id for the one in your particular row.  So an example, if you have something like this (in pseudocode):

 

<apex:dataTable> <apex:column> <apex:inputText value="{!something}" id="theInput"/> </apex:column> <apex:column> <apex:inputText value="{!somethingElse}" onclick="{!alert('{!$Component.theInput}')}"/> </apex:column> </apex:dataTable>

 And say you fill your dataTable with 10 rows.  In ever row if you click on the second inputText, it will alert the id of the first inputText in the same row.  So you'll want to get the id here, and pass it along to your function by doing return closePopup('{!$Component.theInput}');  Then make closePopup take in a String argument and use that in your document.getElementById call.