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
dafunkdafunk 

Cannot access tab through $Component and Path

I am trying to access a tab through getElementById the path is $Component.page.TabPanel.tabTwo

This returns a null - here is the test page - any ideas...

thanks Joe

 

 

<apex:page standardController="Account" showHeader="true" id="page">
<!-- Define Tab panel .css styles -->
<style>
.activeTab {background-color: #236FBD; color:white; background-image:none}
.inactiveTab { background-color: lightgrey; color:black; background-image:none}
</style>

<!-- Create Tab panel -->
<apex:tabPanel switchType="client" selectedTab="name2" id="TabPanel"
tabClass="activeTab" inactiveTabClass="inactiveTab">
<apex:tab label="One" name="name1" id="tabOne">
content for tab one</apex:tab>
<apex:tab label="Two" name="name2" id="tabTwo">
content for tab two</apex:tab>
</apex:tabPanel>
<input type="button" onclick="testPath()" value="Show Path"></input>
<script>
function testPath(){
try{
var s = document.getElementById('{!$Component.page.TabPanel.tabTwo}');
alert('Component:' + s.id);
}catch(error){
alert('Error:' + error.message);
}
}
</script>
</apex:page>

 

Best Answer chosen by Admin (Salesforce Developers) 
Puja_mfsiPuja_mfsi

Hi,

Replace your java script code as below:

<script>
          function testPath(){
               try{
                   var s = document.getElementById('{!$Component.tabTwo}');
                   alert('Component:' + s.id);
                }catch(error){
                         alert('Error:' + error.message);
                }
          }

</script>

 

Please let me know if u have any problem regarding same,and if this post helps u give KUDOS by click on star at left.