0

I have an <apex:tabPanel> with several <apex:tab>.

In my first tab, I have an <apex:commandButton> and I want to switch to the second tab after a click on it. Is it possible ?

Here is my VisualForce page :

<apex:page>
 <apex:tabPanel>
     <apex:tab label="tab1" name="tab1" id="tab1">
         <apex:commandButton onclick="switchToSecondTab()"/>    
     </apex:tab>
     <apex:tab label="tab2" name="tab2" id="tab2">

     </apex:tab>
 </apex:tabPanel>

<script type="text/javascript">>
    function switchToSecondTab() {
        // What do I need to do here to switch to tab2 ?
    }
</script>
</apex:page>
1

Have u tried this [ http://www.infallibletechie.com/2013/02/blog-post.html ]

May this will help you !!!

1

Thanks to @Aryan kapoor's link and with some modifications, I can do what I want.

Here is the code :

VisualForce page :

<apex:page>
     <apex:tabPanel switchType="client" id="panelId" value="{!tabOpt}">
         <apex:tab label="one" name="one" id="one">
             <apex:commandButton action="{!switch}" rerender="panelId"/>    
         </apex:tab>
         <apex:tab label="two" name="two" id="two">

         </apex:tab>
     </apex:tabPanel>
</apex:page>

Apex class :

public String tabOpt {get;set;}

public void switch() {
  tabOpt = 'two';
} 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.