0

I have a button that is set up to call a javascript function to automatically activate a "tab" on a page. When that tab is loaded, there are subtabs that display. I am trying to set it up so that one of the subtabs is also automatically activated when the button is clicked.

Currently I can get the first tab to select, but I can't get the subtab to select. #detailsTab is the id of the first tab. #personal-information is the id of the subtab I am trying to select.

The following is what I have.

This is all in the same file:
HTML:

<button class="button button--primary button--sm" onclick="viewDetials()">View Details</button>

Javascript:

<script type="text/javascript">
    function viewDetials() {
        $("#detailsTab").click();
        personalSubTab();
    }

    window.onload = function personalSubTab() {
        $("#personal-information").click();
    }
</script>
2
  • I tried switching the order of the two functions, but that didn't help either Commented Jul 23, 2015 at 17:45
  • Try your code in bottom of the page b4 body close Commented Jul 23, 2015 at 17:50

3 Answers 3

1

Try combining your functions and adding a short delay for the subtab.

function viewDetials() {
    $("#detailsTab").click();

    setTimeout(function(){
        $("#personal-information").click();
    }, 200);  // This value can be tweaked

}
Sign up to request clarification or add additional context in comments.

3 Comments

that doesnt work either. $("#personal-information").click(); has to be called AFTER the detailsTab is loaded.
It's hard to tell exactly what would work for you without actually being able to see the full code of the page. But does this method work better than my original post?
This worked. I had to tweak the delay, but it works. Thanks!
0

The following will be called when the document is ready.

<script type="text/javascript">
    function viewDetials() {
        $("#detailsTab").click();
        personalSubTab();
    }

    function personalSubTab() {
        $("#personal-information").click();
    }

    // Document ready
    $(function () {
        personalSubTab();
    });
</script>

1 Comment

still doesn't activated the subtab that I am trying to get.
0

I'm not exactly sure what you want to do - but if you want to generate a click event on another button/div use trigger, not click - like this:

function personalSubTab() {
$("#personal-information").trigger('click');}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.