5

The question has been asked a few times before, but none of them are similar to my scenario.

I have jQuery Tabs control that loads my tabs via ajax:

<div id="tabs">
<ul>
    <% if (AccessControll.HasAccess(Url.Action("ViewSchemeInformation","Scheme"))){%>
        <li><a id="tab_1" href="<%= Url.Action("ViewSchemeInformation","Scheme", new {schemeNumber = Model.SchemeNumber}) %>">Information</a></li>
    <%}%>
    <% if (AccessControll.HasAccess(Url.Action("SchemeUpdate", "Scheme"))){%>
        <li><a id="tab_2" href="<%= Url.Action("SchemeUpdate","Scheme", new {schemeNumber = Model.SchemeNumber}) %>">Update</a></li>
    <%}%>
    <%if (AccessControll.HasAccess(Url.Action("MinimumRequirements","Scheme"))){%>
        <li><a id="tab_3" href="<%= Url.Action("MinimumRequirements","Scheme", new {schemeNumber = Model.SchemeNumber}) %>">Minimum Requirements</a></li>
    <%}%>
</ul>

These tabs are shown based on access, so my tab index's are never the same, hence I have added an id to each href.

I link to this specific page from various places and each link must go to this page and select the tab it refers to.

My url will look something like this: http://localhost:34412/Scheme/ViewSchemeDetails/BS-000469800000?activeTab=1

How can I select the tab using jQuery based on the activeTab parameter in my querystring?

Note that number in the querystring always corresponds to the id of my href.

рüффп
  • 5,172
  • 34
  • 67
  • 113
stoic
  • 4,700
  • 13
  • 58
  • 88

2 Answers2

8

Get the query string:

var queryString = window.location.search;

Get the activeTab part:

var activeTab = queryString.match(/\bactiveTab=([^&]*)/)[1];

Select the tab with the right ID:

$('#tab_' + activeTab).click();
David Tang
  • 92,262
  • 30
  • 167
  • 149
  • just to let you know, there there some ie7 issues with the `$('#tab_' + activeTab).click();` – stoic May 20 '11 at 14:08
2
tabs_object.tabs('widget').tabs("option", 'selected', 2);

in your case

tabs_object.tabs('widget').tabs("option", 'selected', activeTab);
kleopatra
  • 51,061
  • 28
  • 99
  • 211
Onaga
  • 21
  • 1