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
mritzmritz 

how to switch tabs on visualforce page using javascript on button click

<apex:page showHeader="false" sidebar="false">
    <!-- 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>
    <script type="text/javascript">
        function next(buttonId){
            //code to show next tab....
            
        }
        function back(buttonId){
            // code to show previous tab...
        }
    </script>        
    <!-- Create Tab panel -->
    <apex:form >
    <apex:tabPanel switchType="client" selectedTab="name2" id="AccountTabPanel"
        tabClass="activeTab" inactiveTabClass="inactiveTab">
        <apex:tab label="One" name="name1" id="tabOne">content for tab one<br/>
            <apex:commandButton value="Next" id="next1" onclick="next(this.id);"/>
        </apex:tab>
        <apex:tab label="Two" name="name2" id="tabTwo">content for tab two<br/>
            <apex:commandButton value="Back" id="back1" onclick="back(this.id);"/>
            <apex:commandButton value="next" id="next2" onclick="next(this.id);"/>
        </apex:tab>
        <apex:tab label="Three" name="tabThree">
            <table style="border:solid; position:center">
                <tr>
                    <td>Field Name</td>
                    <td>Input</td>
                </tr>
                <tr>
                    <td>Name:</td>
                    <td><input type="Text" name="nm"/></td>
                </tr>
            </table>
        
        </apex:tab>
    </apex:tabPanel>
    </apex:form>
</apex:page>

I am creating a custom visual force page having mutiple tabs in TabPanel.
I want to show adjoining tab or previous tab when "next" or "back" buttons are clicked.

please help me with the javascript code to acheive this.

Moreover, i also want to stop users to access tabs on mouseclick
(that means that the user cant switch between tabs by clicking on tab labels)

any help will be appreciated.
 
sandeep sankhlasandeep sankhla
Hi Mritzi,

Please refer below link for similar need
https://developer.salesforce.com/forums/ForumsMain?id=906F000000095ECIAY

You can take reference from aboe code and then you cna implement as per your need..please check with the link and let me know if you need any help in implementig..

Thanks
Sandeep
mritzmritz
@sandeep

The answer choosen there, uses apex function.

It has only two tabs and you can see the no of functions used :-/

I want to acheive same thing using javascript so that i can reuse same function for all next buttons (even if i have 10s of tabs) and same thing for back button.

Please help me with Javascript code.